flat assembler
Message board for the users of flat assembler.

Index > Windows > Some Winsock Functions Questions..

Goto page 1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Hello everyone. Smile I'm learning and learning new things here. I have now focused my mind on winsock programming. But I have so much questions.. I'll discus them here. I found some examples in Google and here also but I don't understand much from there. If anyone can write example with less API functions and less code for those structure I'll be very thankful.. Smile
Code:
#1 Program should connect to some web server (ex: google.com) and send HEAD request and receive result and save in to the buffer.

#2 Program that will be bound to some port (ex: telnet port 23) and when someone will connect, send him some data from program and close connection.

#3 Program that will be bound to some port (ex: telnet port 23) and will receive data from other computer and save it to buffer.

#4 Program that will be infinitely listen connection and will never close it and then will receive data and send back with input. just like a chat..    


P.S I'm saying it again. I already checked on this forum and Google but no one from them is good understandable for me. And 1 more thing. It should be in FASM with easiest source (if possible..) And I think it will be nice tutorial for other beginners too Smile

Thank you for your time everyone Smile
Post 08 Nov 2010, 20:31
View user's profile Send private message Reply with quote
asmhack



Joined: 01 Feb 2008
Posts: 431
asmhack
http://flatassembler.net/examples/quetannon.zip
hope you won't transform it into a badass trojan
Post 09 Nov 2010, 00:14
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
asmhack, maybe you have bad eyes ? Wink
Code:
#1 I found some examples in Google and here also but I don't understand much from there.
#2 If anyone can write example with less API functions and less code for those structure...
#3 P.S I'm saying it again. I already checked on this forum and Google but no one from them is good understandable for me. And 1 more thing. It should be in FASM with easiest source (if possible..) And I think it will be nice tutorial for other beginners too    

I'm not trying to "hack" things just interested how does it work, if so I could just copy source and replace things and done. PLEASE think before posting. Thanks.
Post 09 Nov 2010, 00:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
Overflowz: Show what you have so far. At least give us some confidence that you are trying your best to get something working.

You can't really expect others to write stuff from scratch, it would be easier for others to modify something for you that you are having trouble with.

Most people have limited time available to help out so it would be best for you if you try to make it easier for others to help you. And that means posting some code you are working on and ask specific questions. Usually one question at a time is the way to maximise the desire of others to help.
Post 09 Nov 2010, 01:04
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Allright. I'll show you codes and someone convert main functions from there please. Smile

#1 Program called Headreq http://madwizard.org/download/winsock/headreq_asm.zip

#2 Can't find any example.. just simple as it sounds..

#3 Like reverse of 2, for example server is running on 23 port. Connected to server and sent some data, clicked enter and connection closed and result saved in buffer.

#4 Picnic's Simple Chat. http://board.flatassembler.net/download.php?id=5156

this is all what I mean. Thanks.

Oh and P.S Interesting about difference between Blocking sockets and non-blocking and both examples.
Post 09 Nov 2010, 10:01
View user's profile Send private message Reply with quote
b1528932



Joined: 21 May 2010
Posts: 287
b1528932
its much harder than u think.
you must first understand how windows managwe protocols, what are protocol properties, learn how functions inform you about certain network events (so you implicitly must know well tcp/ip). You need to know internals about your io method (assuming you are not a noob using blocking send/recv thread per client).

And if you want to send http request, you need to learn http, because its insane complicated protocol.

Ive spent much time learning this, and unless you dont plan using this knowleadge to hack something, there is no point wasing your time with it. Goto linux if you want to write 'friendly' programs. Windows is dead when it come to future programming, imho. The only thing keeping it on market is its popularity. Youll see, windows 10 will be opensource based on linux. All windows features will be emulated for backward compatibility.
Post 09 Nov 2010, 14:07
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
b1528932, I know that things already. I'll explain what I don't know right now.
first, what to do first. I mean when WSAStartup initialized, then I'm creating socket and then I have no idea what should be next command for somethings.. I'm trying to learn on windows first, next time I'll use Linux. Just I'm trying to make programs on windows cause many people are using it in my country. I need just simple examples of them.. Smile and BTW I don't understand why IP is converting to other thing, I have question, does that converting IP from big-endian to little-endian ? Hope someone will make examples of that structure what I wrote last post. Thanks.
Post 09 Nov 2010, 14:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
If you want to connect to google.com then you have to knows its IP, so you need to do a DNS lookup first.

Then if you want to connect to a particular service at google.com then you need to know the port to connect to, HTTP=80, HTTPS=443 etc.

Then if you want to send data to google.com on port 80 then you have to know the HTTP protocol details with properly formatted data to send to google.com.

All that is just for #1 on your list. Once you get that all working then you can move to #2 and onwards.
Post 09 Nov 2010, 14:56
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
revolution, I know already that what it should do. But I don't know how to code that. I'll write little example how I'm thinking it would be.
Code:
format PE console 4.0
include 'WIN32AX.INC'
entry main
section '.data' data readable writeable
hSock dd ?
s_data db "HEAD / HTTP/1.1",0
wsaData WSADATA
sin sockaddr_in
sizeof.sin = $ - sockaddr_in
section '.text' code readable executable
proc main
invoke WSAStartup,0202h,wsaData
invoke socket,AF_INET,SOCK_STREAM,0
mov [hSock],eax
...
section '.idata' import data readable
blablabla..    

I have no idea what should I write next to send "s_data" request to server and then receive output back.. I just need that nothing else. On listen I know first I should make socket then bind then listen then accept and done but on send I really don't know. I'm just asking about that examples Smile
Post 09 Nov 2010, 15:03
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
Do a DNS lookup, get the IP for google.com.

hint: invoke gethostbyname, ...
Post 09 Nov 2010, 15:08
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
maybe full example please ? Smile I know gethostbyname I mean I don't know what to do next. I'll write 1 more example after that code how I think it would be.
Code:
invoke gethostbyname,ipBuffer
;I don't know where IP is located now.
invoke connect,[hSock],sin,sizeof.sin
invoke send,[hSock],s_data,sizeof.s_data
invoke ExitProcess,0    

Am I right ?
Post 09 Nov 2010, 15:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
Overflowz wrote:
maybe full example please ? Smile
First result returned by google.

https://encrypted.google.com/search?num=100&hl=en&q=gethostbyname&btnG=Search

BTW: asmhack already gave a full working example but you rejected it. So we have to do this step by step. We can't rush the learning process.


Last edited by revolution on 09 Nov 2010, 15:23; edited 1 time in total
Post 09 Nov 2010, 15:22
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
I saw that but I'm not programmer to understand what that structure means and how to use that too.. I don't have problem about getting host IP. just how to send..
Post 09 Nov 2010, 15:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
Overflowz wrote:
I saw that but I'm not programmer to understand what that structure means and how to use that too.. I don't have problem about getting host IP. just how to send..
You can't send yet, you have to get the IP first, it is not optional. Without the IP you have nowhere to send to.
Post 09 Nov 2010, 15:24
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Urghh I hate English. For example I have IP not site. how to send packets there I don't know what command should be next and next after creating socket..
Post 09 Nov 2010, 15:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
Here is small snippet from some of my code:
Code:
      mov     eax,dword[edx+HTTP_STATE.hostent_buff+hostent.h_addr_list]
  mov     eax,[eax+0]                             ;get first entry in listhwnd
        test    eax,eax
     jz      .cant_find_IP
       mov     eax,[eax+0]                             ;get IP
     test    eax,eax
     jz      .cant_find_IP
       stdcall HTTP_set_IP_address,edx,eax

;...

proc HTTP_set_IP_address uses ebx,state,IP
   mov     ebx,[state]
 mov     eax,[IP]
    mov     [ebx+HTTP_STATE.sock_addr.sin_addr],eax
;...    
edx is a pointer to my internal structures, you can ignore it. Just learn the code for extracting the IP address.
Post 09 Nov 2010, 15:28
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
Once you have the IP stored in the sock_addr structure, next is to set the port.

hint: invoke htons, ...
Post 09 Nov 2010, 15:32
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Sad(((((((( You don't understand me. FORGET everything and try to focus on this:
I have an ip address for example 127.0.0.1
I need to send some data to 127.0.0.1
and I don't know what commands should I use after creating socket.
I need just example not explanation cause I don't understand so much about that things. I can only understand from sources.. Thank you. Brb after 3 hours and I'll post.
Post 09 Nov 2010, 15:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
Overflowz wrote:
I need just example ...
Okay, here a fully tested and working example:

http://flatassembler.net/examples/quetannon.zip

You can safely ignore my attempts to explain this to you step by step and instead read the sources.

When all else fails, read the source. Wink
Post 09 Nov 2010, 15:36
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
... Smile just say u can't help.
asmhack wrote:
http://flatassembler.net/examples/quetannon.zip
hope you won't transform it into a badass trojan
Post 09 Nov 2010, 17:19
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3, 4  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.