55
66# Everything about the bug and firmware https://www.exploit-db.com/exploits/33863
77
8- import os , sys
8+ import sys
99sys .path .append ("../../.." )
1010
1111from qiling import Qiling
1212from qiling .const import QL_VERBOSE
1313from qiling .extensions .afl import ql_afl_fuzz
1414
1515
16- def main (input_file , enable_trace = False ):
16+ def main (input_file : str ):
1717
1818 env_vars = {
1919 "REQUEST_METHOD" : "POST" ,
@@ -24,40 +24,36 @@ def main(input_file, enable_trace=False):
2424 # "CONTENT_LENGTH": "8", # no needed
2525 }
2626
27- ql = Qiling (["./rootfs/htdocs/web/hedwig.cgi" ], "./rootfs" ,
28- verbose = QL_VERBOSE .DEBUG , env = env_vars , console = enable_trace )
27+ ql = Qiling (["./rootfs/htdocs/web/hedwig.cgi" ], "./rootfs" , verbose = QL_VERBOSE .DISABLED , env = env_vars )
2928
30- def place_input_callback (ql : Qiling , input : bytes , _ : int ):
31- env_var = ("HTTP_COOKIE=uid=1234&password=" ).encode ()
32- env_vars = env_var + input + b"\x00 " + (ql .path ).encode () + b"\x00 "
33- ql .mem .write (ql .target_addr , env_vars )
29+ def place_input_callback (ql : Qiling , data : bytes , _ : int ) -> bool :
30+ # construct the payload
31+ payload = b'' .join ((b"HTTP_COOKIE=uid=1234&password=" , bytes (data ), b"\x00 " , ql_path , b"\x00 " ))
3432
35- def start_afl (_ql : Qiling ):
33+ # patch the value of 'HTTP_COOKIE' in memory
34+ ql .mem .write (target_addr , payload )
35+
36+ # payload is in place, we are good to go
37+ return True
3638
39+ def start_afl (_ql : Qiling ):
3740 """
3841 Callback from inside
3942 """
43+
4044 ql_afl_fuzz (_ql , input_file = input_file , place_input_callback = place_input_callback , exits = [ql .os .exit_point ])
4145
42- addr = ql .mem .search ("HTTP_COOKIE=uid=1234&password=" .encode ())
43- ql .target_addr = addr [0 ]
46+ addr = ql .mem .search (b"HTTP_COOKIE=uid=1234&password=" )
47+ target_addr = addr [0 ]
48+ ql_path = ql .path .encode ()
4449
45- main_addr = ql .loader .elf_entry
46- ql .hook_address (callback = start_afl , address = main_addr )
50+ ql .hook_address (start_afl , ql .loader .elf_entry )
4751
48- try :
49- ql .run ()
50- os ._exit (0 )
51- except :
52- if enable_trace :
53- print ("\n Fuzzer Went Shit" )
54- os ._exit (0 )
52+ ql .run ()
5553
5654
5755if __name__ == "__main__" :
58- if len (sys .argv ) == 1 :
56+ if len (sys .argv ) < 2 :
5957 raise ValueError ("No input file provided." )
60- if len (sys .argv ) > 2 and sys .argv [1 ] == "-t" :
61- main (sys .argv [2 ], enable_trace = True )
62- else :
63- main (sys .argv [1 ])
58+
59+ main (sys .argv [1 ])
0 commit comments