diff --git a/monkey/infection_monkey/external_tools/archeologist_bootloader/archeologist.cpp b/monkey/infection_monkey/external_tools/archeologist_bootloader/archeologist.cpp deleted file mode 100644 index 195a1b4e5..000000000 --- a/monkey/infection_monkey/external_tools/archeologist_bootloader/archeologist.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -using namespace std; - -void main() -{ - std::ofstream outfile ("C:/Windows/Temp/test.txt"); - - outfile << "my text here!" << std::endl; - - outfile.close(); -} diff --git a/monkey/infection_monkey/external_tools/archeologist_bootloader/old_machine_bootloader.c b/monkey/infection_monkey/external_tools/archeologist_bootloader/old_machine_bootloader.c new file mode 100644 index 000000000..8f7a6ee98 --- /dev/null +++ b/monkey/infection_monkey/external_tools/archeologist_bootloader/old_machine_bootloader.c @@ -0,0 +1,80 @@ +#include /* printf, sprintf */ +#include /* exit */ +#include /* read, write, close */ +#include /* memcpy, memset */ +#include /* socket, connect */ +#include /* struct sockaddr_in, struct sockaddr */ +#include /* struct hostent, gethostbyname */ + +void error(const char *msg) { perror(msg); exit(0); } + +int main(int argc,char *argv[]) +{ + /* first what are we going to send and where are we going to send it? */ + int portno = 5000; + char *host = "api.somesite.com"; + char *message_fmt = "POST /apikey=%s&command=%s HTTP/1.0\r\n\r\n"; + + struct hostent *server; + struct sockaddr_in serv_addr; + int sockfd, bytes, sent, received, total; + char message[1024],response[4096]; + + /* fill in the parameters */ + sprintf(message,message_fmt,argv[1],argv[2]); + printf("Request:\n%s\n",message); + + /* create the socket */ + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) error("ERROR opening socket"); + + /* lookup the ip address */ + server = gethostbyname(host); + if (server == NULL) error("ERROR, no such host"); + + /* fill in the structure */ + memset(&serv_addr,0,sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(portno); + memcpy(&serv_addr.sin_addr.s_addr,server->h_addr,server->h_length); + + /* connect the socket */ + if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) + error("ERROR connecting"); + + /* send the request */ + total = strlen(message); + sent = 0; + do { + bytes = write(sockfd,message+sent,total-sent); + if (bytes < 0) + error("ERROR writing message to socket"); + if (bytes == 0) + break; + sent+=bytes; + } while (sent < total); + + /* receive the response */ + memset(response,0,sizeof(response)); + total = sizeof(response)-1; + received = 0; + do { + bytes = read(sockfd,response+received,total-received); + if (bytes < 0) + error("ERROR reading response from socket"); + if (bytes == 0) + break; + received+=bytes; + } while (received < total); + + if (received == total) + error("ERROR storing complete response from socket"); + + /* close the socket */ + close(sockfd); + + /* process response */ + printf("Response:\n%s\n",response); + + return 0; +}