Skip to content

Instantly share code, notes, and snippets.

@Zelakolase
Created December 6, 2022 20:35
Show Gist options
  • Save Zelakolase/f1f64fd32147dca54edad8661ca7483e to your computer and use it in GitHub Desktop.
Save Zelakolase/f1f64fd32147dca54edad8661ca7483e to your computer and use it in GitHub Desktop.
A login portal in NASM, HTTP Server using ChatGPT
[bits 32]
section .data
username db \"morad\", 0
username_len equ $-username
password db \"morad\", 0
password_len equ $-password
msg_success db \"Login successful!\", 0
msg_success_len equ $-msg_success
msg_failure db \"Login failed!\", 0
msg_failure_len equ $-msg_failure
section .bss
username_in resb 32
password_in resb 32
section .text
global _start
_start:
; Set up the stack
mov esp, stack_end
; Set up the socket
mov eax, 0x66 ; socketcall
mov ebx, 0x1 ; socket
mov ecx, 0x2 ; AF_INET
mov edx, 0x1 ; SOCK_STREAM
int 0x80
; Save the socket descriptor
mov [sock], eax
; Bind the socket
mov eax, 0x66 ; socketcall
mov ebx, [sock]
mov ecx, 0x10 ; 16 bytes for sockaddr_in
mov edx, sockaddr
int 0x80
; Listen on the socket
mov eax, 0x66 ; socketcall
mov ebx, [sock]
mov ecx, 0x1 ; backlog
int 0x80
; Accept a connection
mov eax, 0x66 ; socketcall
mov ebx, [sock]
mov ecx, 0 ; no sockaddr
mov edx, 0 ; no addrlen
int 0x80
; Save the connection descriptor
mov [conn], eax
; Read the username
mov eax, 0x66 ; socketcall
mov ebx, [conn]
mov ecx, username_in
mov edx, 32
int 0x80
; Read the password
mov eax, 0x66 ; socketcall
mov ebx, [conn]
mov ecx, password_in
mov edx, 32
int 0x80
; Compare the username
mov eax, 0x3d ; strcmp
mov ebx, username
mov ecx, username_in
int 0x80
; Compare the password
cmp eax, 0
jne failure
mov eax, 0x3d ; strcmp
mov ebx, password
mov ecx, password_in
int 0x80
; Check the result
cmp eax, 0
je success
failure:
; Send the failure message
mov eax, 0x66 ; socketcall
mov ebx, [conn]
mov ecx, msg_failure
mov edx, msg_failure_len
int 0x80
jmp exit
success:
; Send the success message
mov eax, 0x66 ; socketcall
mov ebx, [conn]
mov ecx, msg_success
mov edx, msg_success_len
int 0x80
exit:
; Close the connection
mov eax, 0x66 ; socketcall
mov ebx, [conn]
mov ecx, 0
int 0x80
; Close the socket
mov eax, 0x66 ; socketcall
mov ebx, [sock]
mov ecx, 0
int 0x80
; Exit
mov eax, 1 ; exit
mov ebx, 0
int 0x80
section .data
sock dd 0
conn dd 0
stack_end equ $
sockaddr:
dd 0x2 ; AF_INET
dw 0x1 ; port
dd 0x0 ; IP
dd 0x0 ; padding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment