Skip to content

Commit b0d6384

Browse files
committed
Misc examples fixes
1 parent 0d9c722 commit b0d6384

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

examples/fuzzing/dlink_dir815/dir815_mips32el_linux.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
# Everything about the bug and firmware https://www.exploit-db.com/exploits/33863
77

8-
import os,sys
8+
import sys
99
sys.path.append("../../..")
1010

1111
from qiling import Qiling
1212
from qiling.const import QL_VERBOSE
1313
from 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("\nFuzzer Went Shit")
54-
os._exit(0)
52+
ql.run()
5553

5654

5755
if __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])

examples/sality.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def hook_StartServiceA(ql: Qiling, address: int, params):
159159
init_unseen_symbols(ql.amsint32_driver, ntoskrnl.base+0xb7695, b"NtTerminateProcess", 0, "ntoskrnl.exe")
160160
#ql.amsint32_driver.debugger= ":9999"
161161
try:
162-
ql.amsint32_driver.load()
162+
ql.amsint32_driver.run()
163163
return 1
164164
except UcError as e:
165165
print("Load driver error: ", e)

examples/tendaac1518_httpd.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def __vfork(ql: Qiling):
7878

7979
ql.os.set_syscall('vfork', __vfork)
8080

81+
os.unlink(fr'{ROOTFS}/proc/sys/kernel/core_pattern')
82+
8183
ql.run()
8284

8385

0 commit comments

Comments
 (0)