-
Notifications
You must be signed in to change notification settings - Fork 2
/
call_stack_tampering.asm
106 lines (87 loc) · 1.74 KB
/
call_stack_tampering.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
global _start
extern _GetStdHandle@4
extern _WriteFile@20
extern _ExitProcess@4
section .text
call_stack_tamper1:
push call_stack_tamper2
mov ebp, esp
sub esp, 4
push ecx
push 0
lea eax, [ebp - 4]
push eax
push (tamper_now1_end - tamper_now1)
push tamper_now1
push ebx
call _WriteFile@20
pop ecx
add esp, 4
ret
call_stack_tamper2:
add ecx, 0x50
add ecx, 0xD5
push ecx
ret
hello:
; Not Execute this insn
mov ebp, esp
; Function starts from this insn(hello + 2)
mov ebp, esp
; print message
sub esp, 4
push 0
lea eax, [ebp - 4]
push eax
push (not_return_msg_end - not_return_msg)
push not_return_msg
push ebx
call _WriteFile@20
call exit
ret
exit:
; ExitProcess(0)
push 0
call _ExitProcess@4
ret
main:
; DWORD bytes;
; <- prepare local variable
mov ebp, esp
sub esp, 4
; Obfuscate constants(use for call-stack-tampering
mov ecx, hello + 2
sub ecx, 0x100
sub ecx, 0x025
; hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)
; (STD_OUTPUT_HANDLE = -11)
push -11
call _GetStdHandle@4
mov ebx, eax
call call_stack_tamper1
; Never return below
; show 'Hello, World'
; WriteFile( hStdOut, msg, length(msg), &size, 0)
push 0
lea eax, [ebp - 4]
push eax
push (message_end - message)
push message
push ebx
call _WriteFile@20
call exit
; never here
hlt
; Entry point
_start:
call main
ret
message:
db 'Hello, World', 10
message_end:
not_return_msg:
db 'Call Stack Tampered', 10
not_return_msg_end:
tamper_now1:
db 'Tamper Now1...', 10
tamper_now1_end: