Skip to content

Commit 4f0710b

Browse files
authored
Add files via upload
1 parent fbb646b commit 4f0710b

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed

ASM_x86/LinuxAPI_07_uname.asm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
;Example of using the uname API. API calls found in this example program:
2+
; uname, exit
3+
; High level description of what theis example program does:
4+
; Simply calls uname and stores the result in memory pointer
5+
6+
section .text
7+
global _start
8+
9+
_start:
10+
11+
; Get uname data
12+
;------------------------------------------------------------------------------
13+
mov eax, 109 ; uname
14+
mov ebx, sysname ; Pointer to where you want the data
15+
int 0x80
16+
17+
; Exit
18+
;------------------------------------------------------------------------------
19+
mov eax, 1
20+
int 0x80
21+
22+
23+
section .bss
24+
sysname resb 65 ; Probably 'Linux'
25+
nodename resb 65 ; Hostname in my case
26+
release resb 65 ; Kernel version
27+
version resb 65 ; Version details
28+
machine resb 65 ; Architecture

ASM_x86/LinuxAPI_11_sigaction.asm

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
;Example of intercepting a signal with our own handler using the signal API. API calls found in this example program:
2+
; signal, write, exit
3+
; High level description of what theis example program does:
4+
; Set up a signal handler to 'handle_it' using signal API
5+
; Proceed into infinite Loop
6+
; In 'handle_it' tell user that 'ctrl+C'd to fuck off,
7+
; then set up new signal handler to exit if ctrl+C is used
8+
; return to infinite Loop
9+
; If Ctrl+C is pressed again, program prints a message indicating defeat and exits
10+
11+
section .text
12+
global _start
13+
14+
_start:
15+
16+
; Set up signal handler to intercept SIGINT (CTRL+C)
17+
;------------------------------------------------------------------------------
18+
mov eax, 48 ; signal
19+
mov ebx, 2 ; SIGINT
20+
mov ecx, handle_it ; Address to signal handler when catching sigint
21+
int 0x80
22+
23+
; Infinit Loop
24+
;------------------------------------------------------------------------------
25+
iloop:
26+
jmp iloop
27+
28+
; Handler for Interupt Signal
29+
;------------------------------------------------------------------------------
30+
handle_it:
31+
mov eax, 4 ; write
32+
mov ebx, 1 ; stdout
33+
mov ecx, message ; '^C <- Nah, Fuck you!'
34+
mov edx, 19 ; how many bytes to print
35+
int 0x80
36+
mov eax, 48 ; new signal
37+
mov ebx, 2 ; SIGINT
38+
mov ecx, exit ; Exit this time
39+
int 0x80
40+
ret ; but for now, go back to our infinite loop
41+
42+
; Exit
43+
;------------------------------------------------------------------------------
44+
exit:
45+
mov eax, 4 ; write
46+
mov ebx, 1 ; stdout
47+
mov ecx, message2 ; '^C Fine...'
48+
mov edx, 9 ; how many bytes to print
49+
int 0x80
50+
mov eax, 1
51+
int 0x80
52+
53+
section .data
54+
message db ' <- Nah, Fuck you!', 0x0a
55+
message2 db ' Fine...', 0x0a
56+
57+
; All the standard signal codez
58+
;------------------------------------------------------------------------------
59+
; 1 - SIGHUP - Hangup
60+
; 2 - SIGINT - Terminal interrupt
61+
; 3 - SIGQUIT - Terminal quit
62+
; 4 - SIGILL - Illegal instruction
63+
; 5 - SIGTRAP - Trace/breakpoint trap
64+
; 6 - SIGABRT - Abort process
65+
; 7 - SIGBUS - Memory access error
66+
; 8 - SIGFPE - Arithmetic exception
67+
; 9 - SIGKILL - Sure Kill
68+
; 10 - SIGUSR1 - User-defined signal 1
69+
; 11 - SIGSEGV - Invalid memory reference
70+
; 12 - SIGUSR2 - User-defined signal 2
71+
; 13 - SIGPIP - Broken pipe
72+
; 14 - SIGALRM - Real-time timer expired
73+
; 15 - SIGTERM - Terminate process
74+
; 16 - SIGSTKFLT - Stack fault on coprocessor
75+
; 17 - SIGCHLD - Child terminated or stopped
76+
; 18 - SIGCONT - Continue if stopped
77+
; 19 - SIGSTOP - Sure stop
78+
; 20 - SIGTSTP - Terminal stop
79+
; 21 - SIGTTIN - Terminal read from BG
80+
; 22 - SIGTTOU - Terminal write from BG
81+
; 23 - SIGURG - Urgent data on socket
82+
; 24 - SIGXCPU - CPU time limit exceeded
83+
; 25 - SIGXFSZ - File size limit exceeded
84+
; 26 - SIGVTALRM - Virtual timer expired
85+
; 27 - SIGPROF - Profiling timer expired
86+
; 28 - SIGWINCH - Terminal window size change
87+
; 29 - SIGIO/POLL- I/O possible
88+
; 30 - SIGPWR - Power about to fail
89+
; 31 - SIGSYS - Invalid system call

ASM_x86/LinuxAPI_12_kill.asm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; MURDER-SUICIDE
2+
;Example of killing a process with the kill API. API calls found in this example program:
3+
; kill
4+
; Go back in time and identify parent (using ppid API)
5+
; Murder parent, effectively killing current-time self:
6+
; Murder Suicide
7+
8+
section .text
9+
global _start
10+
11+
_start:
12+
13+
; Get Parent Process ID
14+
;------------------------------------------------------------------------------
15+
mov eax, 64 ; get the Parent Process ID of self getppid()
16+
int 0x80
17+
mov [ppid], eax ; make note of Parent process ID
18+
19+
; Kill Parent
20+
;------------------------------------------------------------------------------
21+
mov eax, 37 ; kill
22+
mov ebx, [ppid] ; Parent's process ID (Could be bash, could be gdb)
23+
mov ecx, 9 ; kill -9
24+
int 0x80
25+
26+
section .bss
27+
ppid resb 4
28+
29+
; Some misc notes on return value from kill API call
30+
;------------------------------------------------------------------------------
31+
; You can set the sig field (in ecx) to 0, which doesn't do any killing at all
32+
; but it does offer some good recon about the process with the following
33+
; return codes:
34+
; If response is -3 (ESRCH), the process doesn't exist
35+
; This is a hacky way of seeing if a process ID exists or notes
36+
; If response is -1 (EPERM), you don't have permissions to kill the process
37+
; But it does confirm that the process exists
38+
; If response is 0 (no error), not only does the process exist, but you can kill it

0 commit comments

Comments
 (0)