Download file with socket syscall


 
Thread Tools Search this Thread
Top Forums Programming Download file with socket syscall
# 1  
Old 04-22-2014
Download file with socket syscall

Hello to all
I want download a file in osx intel 64 with NASM , I want to use socket syscall
This is part of my code

Code:
section .data
command      db "GET /test/2.gif HTTP/1.1\r\nHost: 10.1.1.187\r\n\r\n", 0
; url                   db "http://172.16.207.153/test/2.gif", 0

global main
section .text

main:    
      
    ;Socket
    mov rdx, 6                  ; rdx = IPPROTO_TCP = 6
    mov rsi, 1                  ; rsi = AF_NET = 1 
    mov rdi, 2                  ; rdi = SOCK_STREAM = 2 
    mov rax, 0x2000061            ; socket syscall = 97
    syscall                     ; call socket(SOCK_STREAM, AF_NET, IPPROTO_TCP);
    mov r12, rax                ; Save the socket
  
  
    ;Sock_addr
    mov r13, 0xB901010A50000101 ; IP = FFFFFFFF, Port = 5C11(4444)
    mov r9b, 0xFF               ; The sock_addr_in is + FF from where we need it
    sub r13, r9                 ; So we sub 0xFF from it to get the correct value and avoid a null
    push r13                    ; Push it on the stack
    mov r13, rsp                ; Save the sock_addr_in into r13
;       mov r13, 0xB901010A50000002 ; IP = 0A0101B9, Port = 50(80)
;       push r13                    ; Push it on the stack
;       mov r13, rsp                ; Save the sock_addr_in into r13
 
    ;Connect 
    mov rax, 0x2000062            ; connect syscall = 98
    mov rdi, r12                ; move the saved socket fd into rdi
    mov rsi, r13                ; move the saved sock_addr_in into rsi
    add rdx, 0x10               ; add 0x10 to rdx
    syscall                     ; call connect(rdi, rsi, rdx)
   
    ;sendto 
    mov rax, 0x2000085            ; connect syscall = 113
    mov rdi, r12                ; move the saved socket fd into rdi
 
 
   
  
    mov  r14 , command
    mov  rsi, r14                ; move the saved sock_addr_in into rsi
    
    mov  rdx, 0x2e               ; add 0x2e to rdx
    
    mov  rcx, 0
 
    mov  r8, r13
    
    mov  r9, 0x10
    
    syscall                     ; call sendto(rdi, rsi, rdx)
    
    mov     rdi, r12
    mov     rax, 0x2000006 ; close
    syscall
 
    mov     rax, 0x2000001 ; exit
    mov     rdi, 0x0
    syscall

In this code , I can create socket and connect and close it (I see it in wireshark and dtruss don't show error). but sendto syscall not send my command ( wireshark don't show my http request in flow tcp stream and dtruss show -1 err#22 for sendto in return value).

please help me .

Last edited by recher.jack; 04-23-2014 at 02:27 AM..
# 2  
Old 04-22-2014
Moderator's Comments:
Mod Comment Moving to Programming, a more appropriate forum.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

Adding our system call Fedora 18 -new syscall

Hi, I wanna add my own system call to Fedora 18 kernel 3.8.2. From kernel 3.3 I heard there is a new system to add system calls. So where i can find a guides ? I wanna print this text: "Hello world!" in terminal, not dmesg. (4 Replies)
Discussion started by: googz
4 Replies

2. UNIX for Advanced & Expert Users

Process on CPU inside syscall

Hello Experts, If a Solaris process is calling some syscall, and right now execution is inside syscall doing only CPU work, for example the inside simplest times syscall, -> app_func => times << we are here now, we have entered in the times, but not exited yet <= times <- app_func... (9 Replies)
Discussion started by: sant
9 Replies

3. UNIX for Dummies Questions & Answers

is read() syscall really a primitive?

I saw somewhere that describe read() as a primitive. But when I lean signals, it says the read() may be interrupted by a signal. My Question: 1, What is the diffence between primitive and reentrant? 2, Is read() a primitive or reentrant? 3, Are all system calls primitive or reentrant? (2 Replies)
Discussion started by: vistastar
2 Replies

4. IP Networking

Clarification - Setting socket options at the same time when socket is listening

I need clarification on whether it is okay to set socket options on a listening socket simultaneously when it is being used in an accept() call? Following is the scenario:- -- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
Discussion started by: jake24
2 Replies

5. UNIX for Advanced & Expert Users

how to distinguish entry/exit of a syscall when using ptrace?

Hi all, I am using ptrace to keep track of clone syscalls in a program. However, I found that the traced syscall cant be paired. for example, there are some syscalls that have entry, but without exit showing up in the traced sequences. So, is there anyway to distinguish the entry and exit of a... (0 Replies)
Discussion started by: tristartom
0 Replies

6. Programming

socket function to read a webpage (socket.h)

Why does this socket function only read the first 1440 chars of the stream. Why not the whole stream ? I checked it with gdm and valgrind and everything seems correct... #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include... (3 Replies)
Discussion started by: cyler
3 Replies

7. Programming

Fork syscall and related issues

Hi all, i just started started learning system programming and want to pursue a career in the sys prog area. below is the program that use a fork() call. i read in one of the tutorials that parent process and child process uses different address spaces and runs concurrently. that meas each... (2 Replies)
Discussion started by: MrUser
2 Replies

8. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

Hi, I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime. To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
Discussion started by: chandrutiptur
0 Replies

9. Programming

recv syscall for socket programming

I have a question regarding the recv syscall. Suppose I have a client/server and the following exchange of message took place: Client --> Server using multiple send syscalls one after another immediately: send "Packet1" send "Packet2" send "Packet3" Server receives in the... (2 Replies)
Discussion started by: heljy
2 Replies
Login or Register to Ask a Question