This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathvegvisir.py
126 lines (93 loc) · 4.01 KB
/
vegvisir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/python
import os
import json
from app.config import config
from app.core import lldbcontroller as LLDBController
from flask import Flask, request, Response, render_template, jsonify
from flask_cors import CORS
name = "vegvisir"
app = Flask(name ,template_folder="www", static_folder="www/")
app.config.update(
DEBUG=True,
TEMPLATES_AUTO_RELOAD=True
)
CORS(app, supports_credentials=False)
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', 'http://%s:%s'%(config.HOST, config.PORT))
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,auth')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
response.headers.add('Access-Control-Allow-Credentials', 'false')
response.headers.add('Access-Control-Expose-Headers', 'auth')
return response
@app.route('/<path:path>')
def static_proxy(path):
# send_static_file will guess the correct MIME type
return app.send_static_file(path)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/if_target', methods=["GET"])
def if_target():
try:
if lldbContr.ifTarget():
entrypoint = lldbContr.getEntryPoint()
functions = lldbContr.doReturnFunctions()
sections,section_sizes = lldbContr.doReturnSections()
disassembly = lldbContr.capDisassemble(long(entrypoint, 16), 0x100)
strings = lldbContr.doReturnStrings()
context = lldbContr.context()
binary = lldbContr.exe
return jsonify({"success":True, "binary":binary, "entrypoint":entrypoint, "functions":functions,"sections":sections,"section_sizes":section_sizes,"disassembly":disassembly,"strings":strings,"context":context})
else:
print 'No target'
return jsonify({"success":False,"targe":False})
except Exception,e:
return jsonify({"success":False,"error":"%s"%e})
@app.route('/set_target', methods=["POST"])
def set_target():
req = request.json
path = str(req["command"]).replace("target create ","")
if path and os.path.isfile(path):
lldbContr.setTarget(str(path), "")
lldbContr.capstoneinit()
if lldbContr.target:
entrypoint = lldbContr.getEntryPoint()
functions = lldbContr.doReturnFunctions()
sections,section_sizes = lldbContr.doReturnSections()
disassembly = lldbContr.capDisassemble(long(entrypoint,16), 0x100)
strings = lldbContr.doReturnStrings()
context = lldbContr.context()
return jsonify({"success":True, "entrypoint":entrypoint, "functions":functions,"sections":sections,"section_sizes":section_sizes,"disassembly":disassembly,"strings":strings,"context":context})
return jsonify({"success":False, "error":"Please give a valid binary path."})
@app.route('/run_command', methods=['POST'])
def run_command():
req = request.json
command = str(req["command"])
try:
success, op = lldbContr.runCommands(command)
if success:
context = lldbContr.context();
return jsonify({"success":True,"output":op,"context":context})
return jsonify({"success":False,"error":op})
except Exception, e:
return jsonify({"success":False, "error":"There was an error while running the command. Error:%s"%(e)})
@app.route('/get_disassembly', methods=['GET'])
def get_disassembly():
func_name = str(request.args.get("func"))
start_addr = str(request.args.get("start_addr"))
end_addr = str(request.args.get("end_addr"))
disassembly = lldbContr.disassemble(func_name, start_addr, end_addr)
if disassembly:
return jsonify({"success":True, "disassembly":disassembly})
return jsonify({"success":False, "error":"non readable"})
@app.route('/get_entrypoint_disassembly', methods=['GET'])
def get_entrypoint_disassembly():
entrypoint = lldbContr.getEntryPoint()
disassembly = lldbContr.capDisassemble(long(entrypoint,16), 0x100)
if disassembly:
return jsonify({"success":True, "disassembly":disassembly})
return jsonify({"success":False, "error":"non readable"})
if __name__ == '__main__':
lldbContr = LLDBController.LLDBController()
app.run(host=config.HOST, port=config.PORT)