1.头号土拨鼠主要负责,PHP查找关键函数,可自定义定位,我把它命名为土拨鼠一号,挖掘比较开心。
# coding=gbk
import sys,os,re
def spider(script_path,script_type):
final_files = []
for root, dirs, files in os.walk(script_path, topdown=False):
for fi in files:
dfile = os.path.join(root, fi)
if dfile.endswith(script_type):
final_files.append(dfile.replace("\\","/"))
print("[+] 共找到了 {} 个PHP文件".format(len(final_files)))
return final_files
def scanner(files_list,cmd):
for item in files_list:
fp = open(item, "r",encoding="utf-8")
data = fp.readlines()
for line in data:
Code_line = data.index(line) + 1
Now_code = line.strip("\n")
for unsafe in [cmd]:
flag = re.findall(unsafe, Now_code)
if len(flag) != 0:
print("函数: {} ---> 函数所在行: {} ---> 路径: {} " .\
format(flag,Code_line,item))
if __name__ == "__main__":
path = sys.argv[1]
shell = sys.argv[2]
ret = spider(path,".php")
scanner(ret,shell)
2.二号土拨鼠,主要用于监控MWeb页面执行过的SQL语句,在指定页面上访问网页,列出所执行的SQL语句,挖掘SQL注入必备。
# coding=gbk
import pymysql,re
#conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123456', db='mysql', charset='utf8')
#cursor = conn.cursor()
#cursor.execute("SET GLOBAL general_log='ON';")
#cursor.execute("set global general_log_file='C:\mysql.log'")
#conn.commit()
#cursor.close()
#conn.close()
try:
fp = open("C:/mysql.log","r")
sql = fp.readlines()
for item in sql:
temp = item.replace("\n","").split('\t')
if re.search("Connect",temp[1]) == None and temp[2] != "":
print("状态:{} ---> 执行语句: {}".format(temp[1],temp[2]))
open("C:/mysql.log","w")
except Exception:
open("C:/mysql.log", "w")
exit()
3.随便演示一下使用方法,随便一个网页,找一个带后缀的页面地址 http://lyshark.com/xhcms/?r=software&cid=1 使用第二个土拨鼠查询其所执行过的SQL语句,可发现如下代码。
我们选择 SELECT * FROM download WHERE 这条可能存在注入,使用一号土拨鼠搜索关键字,查询文件所在位置。
选择第二个,第一个需要登陆才能利用,没什么价值,如下,此处无法绕过$id=addslashes($_GET['cid']); 会将单引号闭合,但查询语句中存在单引号,一旦闭合将自动转义,此处没办法。
紧接着地13行有一条update虽然存在过滤,但是不存在单引号,尝试一下能不能闭合?发现不行,此处SQL语句没有被执行
继续找到另一个存在id的页面,http://lyshark.com/xhcms/?r=content&cid=1 并尝试监控是否有SQL执行,因为上方我们知道单引号过滤,这里我们找一个没有单引号的SQL语句。UPDATE content SET hit = hit+1 WHERE id=1
二号土拨鼠挖掘,直接搜索这条SQL语句是在那个文件中的。
函数: ['UPDATE content SET hit = hit+1 WHERE id='] ---> 函数所在行: 19 ---> 路径: D:/phpstudy/WWW/xhcms/files/content.php
此处代码很有趣,虽然 $id=addslashes($_GET['cid']); 过滤掉单引号,但是下方的SQL语句显然不需要闭合单引号 $query = "UPDATE content SET hit = hit+1 WHERE id=$id"; 也就是说上方的过滤是作废了,我们尝试编写这样一条SQL语句。
UPDATE content SET hit = hit+1 WHERE id=1 OR extractvalue(1,concat(0x7e,version())) #'
测试可以爆出数据,说明注入确实存在,是一条update注入。
直接放入SQLmap 跑一下,可以直接脱裤了。
sqlmap.py -u "http://lyshark.com/xhcms/?r=content&cid=1" --dbs