Homebrew Homebrew Development

  • Thread starter Thread starter aliak11
  • Start date Start date
  • Views Views 1,475,367
  • Replies Replies 6,048
  • Likes Likes 54
(Needed) Disclaimer: Never tried to do such a project so this is also a motivation of why i'm trying to do it. <.<

Does someone know a convenient way for uploading a file on a host with 3DS without using FTP (cause my host company looks like doesn't allow multiple FTP users and i won't put my FTP credential in a reversable homebrew) which doesn't need user interaction? (So for example, no POST method).

It depends on what kind of connections your server allows. POST doesn't require user interaction, and if you are using a simple shared host that would be the best option. Check this example out: http://curl.haxx.se/libcurl/c/fileupload.html
Porting libcurl to the 3ds shouldn't be hard, you would only need to change some socket functions.
 
It depends on what kind of connections your server allows. POST doesn't require user interaction, and if you are using a simple shared host that would be the best option. Check this example out: http://curl.haxx.se/libcurl/c/fileupload.html
Porting libcurl to the 3ds shouldn't be hard, you would only need to change some socket functions.

It allows HTTP, HTTPS, SSH, FTP, SFTP connections for sure.
 
It allows HTTP, HTTPS, SSH, FTP, SFTP connections for sure.
SSH, FTP, and SFTP would all have the same problems with authentication. With HTTP you can use POST or GET, but GET is not supposed to be used for file upload and you would be limited to the max url length and ASCII data only.
So my suggestion would be use POST, you can even use the HTTP service for it. Unless you want to get another server to act as a bridge, which would probably make things more complicated.
 
SSH, FTP, and SFTP would all have the same problems with authentication. With HTTP you can use POST or GET, but GET is not supposed to be used for file upload and you would be limited to the max url length and ASCII data only.
So my suggestion would be use POST, you can even use the HTTP service for it. Unless you want to get another server to act as a bridge, which would probably make things more complicated.

Is there some example on a POST upload without libcurl? (I prefer to write the few functions i need by my own if possible instead of porting such a big library).
 
I don't know. But all you need is to write the POST header and send it.

Mmmhhhh, how can i send it to a selected php target?

This is what i'm doing:

Code:
sprintf(send,"POST /path HTTP/1.0\r\nContent-Disposition: " \
          "form-data; name=\"l\"\r\n\r\nID\r\n" \
          "form-data; name=\"p\"\r\n\r\nPASS\r\n" \
          "form-data; name=\"save\"; filename=\"file.txt\"\r\n" \
          "Content-Type: application/octet-stream\r\nContent-Length: 14\r\n\r\n" \
          "this is a test");

As IP i'm using the host one (got with gesthostbyname) (File is not index ones)
 
Last edited by Rinnegatamante,
Mmmhhhh, how can i send it to a selected php target?

This is what i'm doing:

Code:
sprintf(send,"POST /path HTTP/1.0\r\nContent-Disposition: " \
          "form-data; name=\"l\"\r\n\r\nID\r\n" \
          "form-data; name=\"p\"\r\n\r\nPASS\r\n" \
          "form-data; name=\"save\"; filename=\"file.txt\"\r\n" \
          "Content-Type: application/octet-stream\r\nContent-Length: 14\r\n\r\n" \
          "this is a test");

As IP i'm using the host one (got with gesthostbyname) (File is not index ones)
You want to send the data as multipart/form-data
 
How can it be set? I've just grabbed this header with Tamper Data from a working PHP testscript: http://rinnegatamante.it/TSOI/test.php
Uhmm, if you use chrome look at the developers console network tab.
You will get something like this
Code:
POST /TSOI/uploader.php HTTP/1.1
Host: rinnegatamante.it
Content-Length: 372
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryhkknXjQyze3kErGq

------WebKitFormBoundaryhkknXjQyze3kErGq
Content-Disposition: form-data; name="l"

test
------WebKitFormBoundaryhkknXjQyze3kErGq
Content-Disposition: form-data; name="p"

test
------WebKitFormBoundaryhkknXjQyze3kErGq
Content-Disposition: form-data; name="save"; filename="test.txt"
Content-Type: text/plain


------WebKitFormBoundaryhkknXjQyze3kErGq--
Which is what you. (Chrome doesn't show the file content on the payload part thats why its a blank line)
 
Code:
int main(int argc,char** argv){

   // Getting IP
   char* host = (char*)(argv[1]);
   char* cia_file = (char*)(argv[2]);
  
   // Creating client socket
   Socket* my_socket = (Socket*) malloc(sizeof(Socket));
   memset(&my_socket->addrTo, '0', sizeof(my_socket->addrTo));
   my_socket->addrTo.sin_family = AF_INET;
   my_socket->addrTo.sin_port = htons(80);
   my_socket->addrTo.sin_addr.s_addr = inet_addr(host);
   my_socket->sock = socket(AF_INET, SOCK_STREAM, 0);
   if (my_socket->sock < 0){
     printf("\nFailed creating socket.");  
     return -1;
   }else printf("\nSocket created on port 80");
   fflush(stdout);
  
   // Connecting to the server
  
   char* header = malloc(1048576);
  
   sprintf(header,"POST /TSOI/uploader.php HTTP/1.1\r\n" \
          "Host: %s\r\n" \
          "Content-Length; 27\r\n" \
          "Content-Type: multipart/form-data; boundary=startContent\r\n\r\n" \
          "--startContent\r\n" \
          "Content-Disposition: form-data; name=\"l\"\r\n" \
          "\r\nABCDE\r\n" \
          "--startContent\r\n" \
          "Content-Disposition: form-data; name=\"p\"\r\n" \
          "\r\nABCDEFGH\r\n" \
          "--startContent\r\n" \
          "Content-Disposition: form-data; name=\"save\"; filename=\"test.txt\"\r\n" \
          "Content-Type: text/plain\r\n"
          "\r\nthis is a test\r\n" \
          "--startContent\r\n", host);
        
   int err = connect(my_socket->sock, (struct sockaddr*)&my_socket->addrTo, sizeof(my_socket->addrTo));
   if (err < 0 ){
     printf("\nFailed connecting server.");
     close(my_socket->sock);
     return -1;
   }else printf("\nConnection estabilished...");
   fflush(stdout);
  
   send(my_socket->sock, header, 1048576, 0);
  
   fflush(stdout);
   close(my_socket->sock);
   free(header);
   return 1;
  
}

Tried with this and still doesn't work :/ (as IP i'm using 46.30.212.51)

--------------------- MERGED ---------------------------

Looks like it send a malformed packet and server doesn't found the page:

malformed.png
 
Last edited by Rinnegatamante,
Code:
int main(int argc,char** argv){

   // Getting IP
   char* host = (char*)(argv[1]);
   char* cia_file = (char*)(argv[2]);
 
   // Creating client socket
   Socket* my_socket = (Socket*) malloc(sizeof(Socket));
   memset(&my_socket->addrTo, '0', sizeof(my_socket->addrTo));
   my_socket->addrTo.sin_family = AF_INET;
   my_socket->addrTo.sin_port = htons(80);
   my_socket->addrTo.sin_addr.s_addr = inet_addr(host);
   my_socket->sock = socket(AF_INET, SOCK_STREAM, 0);
   if (my_socket->sock < 0){
     printf("\nFailed creating socket."); 
     return -1;
   }else printf("\nSocket created on port 80");
   fflush(stdout);
 
   // Connecting to the server
 
   char* header = malloc(1048576);
 
   sprintf(header,"POST /TSOI/uploader.php HTTP/1.1\r\n" \
          "Host: %s\r\n" \
          "Content-Length; 27\r\n" \
          "Content-Type: multipart/form-data; boundary=startContent\r\n\r\n" \
          "--startContent\r\n" \
          "Content-Disposition: form-data; name=\"l\"\r\n" \
          "\r\nABCDE\r\n" \
          "--startContent\r\n" \
          "Content-Disposition: form-data; name=\"p\"\r\n" \
          "\r\nABCDEFGH\r\n" \
          "--startContent\r\n" \
          "Content-Disposition: form-data; name=\"save\"; filename=\"test.txt\"\r\n" \
          "Content-Type: text/plain\r\n"
          "\r\nthis is a test\r\n" \
          "--startContent\r\n", host);
       
   int err = connect(my_socket->sock, (struct sockaddr*)&my_socket->addrTo, sizeof(my_socket->addrTo));
   if (err < 0 ){
     printf("\nFailed connecting server.");
     close(my_socket->sock);
     return -1;
   }else printf("\nConnection estabilished...");
   fflush(stdout);
 
   send(my_socket->sock, header, 1048576, 0);
 
   fflush(stdout);
   close(my_socket->sock);
   free(header);
   return 1;
 
}

Tried with this and still doesn't work :/ (as IP i'm using 46.30.212.51)

--------------------- MERGED ---------------------------

Looks like it send a malformed packet and server doesn't found the page:

Yes you have some problems with that request.
First the host has to be your domain name, because of the shared ip.
And you need to end the request with a new line, so add one more \r\n
 
Still nothing, i get an OK and then a BAD REQUEST as responde from the server.

--------------------- MERGED ---------------------------

I solved the BAD REQUEST problem but it still doesn't load the file on the host. Could it be a problem in content-length? How can i calculate it?
 
Last edited by Rinnegatamante,
Still nothing, i get an OK and then a BAD REQUEST as responde from the server.

--------------------- MERGED ---------------------------

I solved the BAD REQUEST problem but it still doesn't load the file on the host. Could it be a problem in content-length? How can i calculate it?
I believe that the content-length is the length of the "payload", so everything after the header counts.
Basically everything that comes after this line:
Code:
"Content-Type: multipart/form-data; boundary=startContent\r\n\r\n"
including the boundaries
 
Using this make BAD REQUEST reappear:

Code:
sprintf(header_bottom, "----startContent\r\n" \
          "Content-Disposition: form-data; name=\"l\"\r\n" \
          "\r\nASD\r\n" \
          "----startContent\r\n" \
          "Content-Disposition: form-data; name=\"p\"\r\n" \
          "\r\nLOL\r\n" \
          "----startContent\r\n" \
          "Content-Disposition: form-data; name=\"save\"; filename=\"test.txt\"\r\n" \
          "Content-Type: text/plain\r\n"
          "\r\nthis is a test\r\n" \
          "----startContent--\r\n");
   
   sprintf(header,"POST /TSOI/uploader.php HTTP/1.1\r\n" \
          "Host: rinnegatamante.it\r\n" \
          "Content-Length: %i\r\n%s" \
          "Content-Type: multipart/form-data; boundary=----startContent\r\n\r\n", strlen(header_bottom), header_bottom);

--------------------- MERGED ---------------------------

Whoops my bad, i made a mystake in %s position
 
Using this make BAD REQUEST reappear:

Code:
sprintf(header_bottom, "----startContent\r\n" \
          "Content-Disposition: form-data; name=\"l\"\r\n" \
          "\r\nASD\r\n" \
          "----startContent\r\n" \
          "Content-Disposition: form-data; name=\"p\"\r\n" \
          "\r\nLOL\r\n" \
          "----startContent\r\n" \
          "Content-Disposition: form-data; name=\"save\"; filename=\"test.txt\"\r\n" \
          "Content-Type: text/plain\r\n"
          "\r\nthis is a test\r\n" \
          "----startContent--\r\n");
  
   sprintf(header,"POST /TSOI/uploader.php HTTP/1.1\r\n" \
          "Host: rinnegatamante.it\r\n" \
          "Content-Length: %i\r\n" \
          "Content-Type: multipart/form-data; boundary=----startContent\r\n\r\n" \
          "%s\r\n", strlen(header_bottom), header_bottom);
Try that
 
Looks like uploading now is detected but fails?

Code:
if (move_uploaded_file($_FILES['save']['tmp_name'], $uploadfile)) {
         echo "File is valid, and was successfully uploaded.\n";
       } else {
         echo "Possible file upload attack!\n";
       }

       echo 'Here is some more debugging info:';
       print_r($_FILES);

This part of PHP script returns this as output:
Code:
Possible file upload attack!
Here is some more debugging info:Array
(
)

--------------------- MERGED ---------------------------

Got it to work, seems boundaries need two more "-" char. Thanks for your help MasterFeizz <3.
 
Looks like uploading now is detected but fails?

Code:
if (move_uploaded_file($_FILES['save']['tmp_name'], $uploadfile)) {
         echo "File is valid, and was successfully uploaded.\n";
       } else {
         echo "Possible file upload attack!\n";
       }

       echo 'Here is some more debugging info:';
       print_r($_FILES);

This part of PHP script returns this as output:
Code:
Possible file upload attack!
Here is some more debugging info:Array
(
)

--------------------- MERGED ---------------------------

Got it to work, seems boundaries need two more "-" char. Thanks for your help MasterFeizz <3.

Glad to help.

Edit: Also, may I ask what you are going to use this for?
 
Glad to help.

Edit: Also, may I ask what you are going to use this for?

Just to try something now, i decided to write a tool for 3DS/PC to share save for TBOI (so when you finish playing to TBOI on PC or 3DS, you can auto-send new save to the server host and grab it automatically on PC/3DS when you want to play it).
 
Just to try something now, i decided to write a tool for 3DS/PC to share save for TBOI (so when you finish playing to TBOI on PC or 3DS, you can auto-send new save to the server host and grab it automatically on PC/3DS when you want to play it).
Awesome!!! But now people are going to beg you for a cloud save manager.
 

Site & Scene News

Popular threads in this forum