Last active
August 25, 2016 15:31
-
-
Save khanzf/de941a575bf400197df574b91078c99c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Just a little bit of code to prove to myself that I could actually write in assembly | |
# To run this, do: | |
# as code.s -o code.o ; ld code.o -o code ; ./code | |
# If you want to debug, run it with strace: strace ./code | |
# Setup a netcat listener on port 31337 | |
# How to do a syscall: http://cs.lmu.edu/~ray/notes/linuxsyscalls/ | |
# List of syscalls: https://filippo.io/linux-syscall-table/ | |
.data | |
message: | |
.asciz "bismillah\r\n" | |
sockaddr_in: | |
.short 2 # family (TCP) | |
.short 27002 # port (31337) | |
.long 16777343 # addr (127.0.0.1) | |
.byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 # zero (buncha zeros!) | |
.global _start | |
.text | |
_start: | |
# Update the basepoint | |
movq %rsp, %rbp | |
# 4 for socket | |
# 4 for he socket variable | |
sub $0x8, %rsp | |
# Socket syscall | |
movq $41, %rax # Socket syscall | |
movq $2, %rdi | |
movq $1, %rsi | |
movq $0, %rdx | |
syscall | |
mov %rax, -0x4(%rbp) # Record the result | |
# Connect syscall | |
movq $42, %rax # Connect syscall | |
movq -0x4(%rbp), %rdi | |
movq $sockaddr_in, %rsi | |
movq $16, %rdx | |
syscall | |
# mov %rax, -0x8(%rbp) # Record the result | |
# Write a message | |
movq $1, %rax # Write Syscall | |
movq -0x4(%rbp), %rdi | |
movq $message, %rsi | |
movq $12, %rdx # Length of message | |
syscall | |
# Need to exit the program, exit(0) | |
movq $60, %rax # Exit syscall | |
movq $0, %rdi # exit(0) | |
syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment