File: test_sp.c

package info (click to toggle)
radare2 0.9.6-3.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 17,496 kB
  • ctags: 45,959
  • sloc: ansic: 240,999; sh: 3,645; makefile: 2,520; python: 1,212; asm: 312; ruby: 214; awk: 209; perl: 188; lisp: 169; java: 23; xml: 17; php: 6
file content (45 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download | duplicates (4)
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
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "sp.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define RPC_HOST "127.0.0.1"
#define RPC_PORT 8181

int main(int argc, char **argv)
{
	int fd, l, con, opt = 1;
	struct sockaddr_in in, in1;
        char *arg[] = {"/bin/sh", 0};

	l = sizeof(in1);

        memset(&in, 0, sizeof(in));
        in.sin_port = htons(3223);
        in.sin_family = AF_INET;

	rpc_init(RPC_HOST, RPC_PORT);

	fd = sys_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	printf("socket: %i\n", fd);
	printf("setsockopt: %i\n", setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, \
			 &opt, sizeof(opt)));
	printf("bind: %i\n", sys_bind(fd, &in, sizeof(in)));
	printf("listen: %i\n", sys_listen(fd, 5));
	con = sys_accept(fd, &in1, &l);
	printf("accept: %i\n", con);
	printf("dup2: %i\n", sys_dup2(con, 0));
	printf("dup2: %i\n", sys_dup2(con, 1));
	printf("dup2: %i\n", sys_dup2(con, 2));
	sys_execve(arg[0], arg, 0);

	return 0;
}