#1.php $s = $_GET['s']; if(is_numeric($s)){ echo get_one("select id from admin where id=".$s); }else{ echo "error"; }
$s = 23; is_numeric($s)==True; echo get_one("select id from admin where id=23");
while b!=0 if a>b a:= a-b else b:= b-a return a
from phply.phpparse import parser
example = "{C}" lexer = phplex.lexer.clone() output = parser.parse(example, lexer=lexer) for i in output: print i out: Assignment(Variable('$s'), 'hello world', False) Echo([Variable('$s')])
def tf(string): lexer = phplex.lexer.clone() output = parser.parse(string, lexer=lexer) return output example = "" for i in tf(example): print i out: Assignment(Variable('$a'), ArrayOffset(Variable('$_GET'), 's'), False) Echo([Variable('$a')])So,一切现在看起来清晰可见,我们接下来要做的是什么?表示成有限状态机?听起来是不是想打我,那换种说法,我们需要的是让变量能够转变成我们的输入,完成 https://xxx.com/1.php?=23 到 $s = $_GET['id'] 的映射,然后我们需要让程序一步步的执行。然后看最终执行到哪。那么,How? 刚才我们已经说过,现在的程序的每个逻辑都是我们可以操作的对象,所以只需要替换他就行了。
seq = [] for i in tf(example): if 'expr' in i.__dict__.keys(): if i.__dict__['expr'].__dict__['node']==Variable('$_GET'): seq.append(tf("")[0]) continue seq.append(i) for i in seq: print i Assignment(Variable('$a'), 'hello fuck', False) Echo([Variable('$a')])那么接下开我们需要做的就是执行他。我们会建立一个eval的函数,让python的解释器来执行php的代码。
def php_eval(nodes): body = [] for node in nodes: stmt = pythonast.to_stmt(pythonast.from_phpast(node)) body.append(stmt) code = ast.Module(body) comp = compile(code, '', mode='exec') eval(comp,globals())请注意,既然说了最终是由python的解释器来执行,那么像echo这种php有的函数python就没有,我们就需要自己实现一下,或者你也可以传递给php执行。因为我没转php所以就简单写一个实现。
def echo(*objs): for obj in objs: sys.stdout.write(str(obj))最后,执行。
php_eval(seq) out: hello fuck这样我们就可以用程序自动HOOK 逻辑a 和逻辑b,然后通过fuzz挖掘其是否存在漏洞。
$string = $_POST['string']; $string = str_replace("select","\se\lect",$string) $string = str_replace("*","",$string) get_one($string);我们只需要 先注入一个 string , 去触发规则,然后再根据写好的混淆规则对sql做变形,那么就可以达到自动bypass的目的。
如对本文有疑问, 点击进行留言回复!!
网友评论