Contribute  :  Web Resources  :  Past Polls  :  Site Statistics  :  Downloads  :  Forum  
    BiW ReversingThe challenge is yours    
 Welcome to BiW Reversing
 Tuesday, October 16 2018 @ 09:15 PM CEST
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ASM Socket programming

 
Post new topic   Reply to topic    www.reversing.be Forum Index -> Coding Corner
View previous topic :: View next topic  
Author Message
sharpe
Frequent poster
Frequent poster


Joined: 20 Mar 2005
Posts: 65

PostPosted: Thu Jun 07, 2007 7:51 pm    Post subject: ASM Socket programming Reply with quote

Hi board,

I am looking for a nice tut about socket programming in ASM. Any help would be much appreciated!

Best,
sharpe.
Back to top
View user's profile Send private message Visit poster's website
detten
Site Admin


Joined: 05 Feb 2005
Posts: 317

PostPosted: Thu Jun 07, 2007 8:19 pm    Post subject: Reply with quote

I remember there was a link to such example on the oldest biw page.
I found a cripple copy of it here, http://home.tiscalinet.be/detten/index.htm

The very start of BiW, those were the days... :p

Anyway, in the coding section there was a HTTP downloader code snippet by iczelion. Here is the link :
http://win32assembly.online.fr/files/http15.zip

I explains how to use winsocks in masm Smile

_________________
Ignorance is bliss, knowledge is power
Back to top
View user's profile Send private message Visit poster's website
sharpe
Frequent poster
Frequent poster


Joined: 20 Mar 2005
Posts: 65

PostPosted: Thu Jun 07, 2007 8:38 pm    Post subject: Reply with quote

Ah yeah, the old BIW page looks pretty snazzy Very Happy

Thanks for the link to the programme, it's just what I am looking for.

BTW, what does BIW stand for? Sorry if it's obvious and I overlooked it somewhere.
Back to top
View user's profile Send private message Visit poster's website
detten
Site Admin


Joined: 05 Feb 2005
Posts: 317

PostPosted: Fri Jun 08, 2007 5:09 pm    Post subject: Reply with quote

There is no meaningful explanation to that question Wink
_________________
Ignorance is bliss, knowledge is power
Back to top
View user's profile Send private message Visit poster's website
sharpe
Frequent poster
Frequent poster


Joined: 20 Mar 2005
Posts: 65

PostPosted: Tue Jun 12, 2007 6:27 am    Post subject: Reply with quote

Right then, I've been doing some socket programming and have stumbled across a small problem. Here is some code:

Code:
ConnectSocket PROC
   ; mov sock,0
   invoke socket,PF_INET,SOCK_STREAM,0
   cmp eax,INVALID_SOCKET
   jz @return
      mov sock,eax
      invoke inet_addr,addr RemoteHost
      cmp eax,INADDR_NONE
      jz @isip
         invoke gethostbyname,addr RemoteHost
      @isip:
      mov SocketAddress.sin_addr,eax
      mov SocketAddress.sin_family,AF_INET
      mov DestPort,80
      invoke htons,DestPort
      mov SocketAddress.sin_port,ax
      invoke connect,sock,addr SocketAddress,SIZEOF SocketAddress   
      invoke WSAGetLastError
   @return:
   ret
ConnectSocket endp


When I get to the connect API I get FFFFFFFFh as a result. When I call WSAGetLastError I get 10049 as the error which is this according to MSDN:

Quote:
Cannot assign requested address. The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer. This can also result from connect, sendto, WSAConnect, WSAJoinLeaf, or WSASendTo when the remote address or port is not valid for a remote computer (for example, address or port 0).


This error is related to the host and port which may be incorrect. Here is my data for this:

Code:

RemoteHost      db   "localhost",0
GetRequest      db   "GET /cmd.txt HTTP/1.0",0dh,0ah
                 db    "Host: localhost",0dh,0ah,0dh,0ah,0


I have a feeling that it has to do with the format of the RemoteHost and port but I am uncertain.

Can anyone spot the error?

I look forward to any help I can get!
Best,
sharpe.
Back to top
View user's profile Send private message Visit poster's website
stingduk
Regular
Regular


Joined: 19 Feb 2005
Posts: 148

PostPosted: Tue Jun 12, 2007 9:10 am    Post subject: Reply with quote

iirc localhost string is not acceptable but you need a formatted ip address there

localhost == 127.0.0.1

never dablled much in network programs but

you should google for beejs socket programming tutorials

they make many things very very clear

though they arent assembly but c

i think you can find borland c++ compiler for free compile them and then
laod them into ollydbg for asm feeling Smile

ok this is what i meant

Code:

#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define DEST_IP   "10.12.110.57"
#define DEST_PORT 23

int main(void)
{
    int sockfd;
    struct sockaddr_in dest_addr;   // will hold the destination addr

    sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking!

    dest_addr.sin_family = AF_INET;          // host byte order
    dest_addr.sin_port = htons(DEST_PORT);   // short, network byte order
    dest_addr.sin_addr.s_addr = inet_addr(DEST_IP);
    memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);

    // don't forget to error check the connect()!
    connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));


http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#connect

ifyou are on purely windows platform take a look atcompiling for windows
in that platform before you go further

its just a matter of chenged syntaxes and some prefixes and suffixes that is different between windows and linux
Back to top
View user's profile Send private message
sharpe
Frequent poster
Frequent poster


Joined: 20 Mar 2005
Posts: 65

PostPosted: Tue Jun 12, 2007 2:10 pm    Post subject: Reply with quote

Silly silly..

HEre is the problem:

Code:
cmp eax,INADDR_NONE
jz @isip


not paying attention.

Thanks for all your help Surprised)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.reversing.be Forum Index -> Coding Corner All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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 can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
 Copyright © 2018 BiW Reversing
 All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.06 seconds