Skip to content

Instantly share code, notes, and snippets.

@tormath1
Created June 3, 2020 18:18
Show Gist options
  • Save tormath1/14807a3fc30e22c1a69365951c71a124 to your computer and use it in GitHub Desktop.
Save tormath1/14807a3fc30e22c1a69365951c71a124 to your computer and use it in GitHub Desktop.
IpV6 - socket connect - assembly 64bits
$ cat > connect.asm << EOF
SECTION .text
global _start
_start:
xor rax, rax ; init 0
xor rdx, rdx ; init 0
xor rsi, rsi ; init 0
xor rdi, rdi ; init 0
_socket:
mov rdi, 0x0A ; family AF_INET6
mov rsi, 0x01 ; type SOCK_STREAM
mov rdx, 0x06 ; protocol TCP
mov rax, 0x29 ; create socket
syscall
mov rdi, rax ; save the file descriptor (the socket) in rdi
_connect:
xor rax, rax ; reset rax
push rax ; push the scope ID (0)
push dword 0x01 ; start to push the localhost address ::1
push rax ; pushing
push rax ; pushing
push rax ; pushing
push rax ; push the flow control (0)
push word 0x32 ; port 12800
push word 0x0A ; family AF_INET6
mov rsi, rsp ; move address of stack pointer into ecx
mov rdx, 0x1c ; get the length of the address: family - port - ip
mov rax, 42 ; syscall for connect
syscall
_exit:
xor rax, rax ; reset rax
mov rbx, rax ; store 0 in rbx
mov rax, 60 ; call exit
syscall
EOF
$ nasm -f elf64 connect.asm
$ ld -o ./connect ./connect.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment