- Instalar got y lowdb
 - Generar toda la información necesaria desde onionoo y guardalo como 
tor-data.js - Utiliza la función 
isTor(req)para filtrar el trafico en tu servidorserver.js. - Instalar dependencias 
npm install got lowdb - Arrancar el servidor 
node server 
          Created
          August 13, 2019 18:03 
        
      - 
      
 - 
        
Save UlisesGascon/a07847fd6bff2625e9b6ca6bf03fe708 to your computer and use it in GitHub Desktop.  
     Identificar trafico de tor
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const http = require('http'); | |
| const {isTor, onReady } = require('./tor-data') | |
| console.log("Data confirmation...") | |
| onReady() | |
| http.createServer((req, res) => { | |
| let msg = '<h1>😥 Hello Internet User!</h1>' | |
| if(isTor(req)) { | |
| msg = '<h1>👹 Hello Onion User!</h1>' | |
| } | |
| res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"}); | |
| res.write(msg); | |
| }).listen(3000); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const got = require('got'); | |
| const low = require('lowdb') | |
| const FileSync = require('lowdb/adapters/FileSync') | |
| const adapter = new FileSync('db.json') | |
| const db = low(adapter) | |
| db.defaults({ | |
| tor: { | |
| exit_nodes: [], | |
| raw: {} | |
| } | |
| }) | |
| .write(); | |
| const allData = () => { | |
| return db.get('tor.raw').value() | |
| } | |
| const allExitNodes = () => { | |
| return db.get('tor.exit_nodes').value() | |
| } | |
| const isExitNode = (ip) => { | |
| const relays = db.get('tor.exit_nodes').value(); | |
| return relays.includes(ip) | |
| } | |
| const onReady = async () => { | |
| const data = db.get('tor.raw').value() | |
| if(!data.relays){ | |
| await updateList() | |
| } | |
| return true; | |
| } | |
| const updateList = async () => { | |
| try { | |
| const response = await got('https://onionoo.torproject.org/details'); | |
| const rawData = JSON.parse(response.body); | |
| db.set('tor.raw', rawData).write() | |
| db.set('tor.exit_nodes', rawData.relays.filter(relay => relay.flags.includes("Exit") && relay.exit_addresses).map(relay => relay.exit_addresses).flat()).write() | |
| } catch (error) { | |
| console.log(error.response.body); | |
| throw error; | |
| } | |
| } | |
| function getUserIp (req) { | |
| let ip = req.connection.remoteAddress | |
| if (ip.substr(0, 7) == "::ffff:") { | |
| ip = ip.substr(7) | |
| } | |
| return ip | |
| } | |
| function isTor (req){ | |
| const ip = getUserIp(req) | |
| return isExitNode(ip) | |
| } | |
| setInterval(() => { | |
| console.log("[TOR][LIST] Time to update!") | |
| updateList(); | |
| }, 600000) | |
| module.exports = {getUserIp, isTor, allData, allExitNodes, isExitNode, onReady } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment