Permalink
Browse files

implemented all original micetrap services

  • Loading branch information...
1 parent 1e75df1 commit 36da7a47d6b426410e8bf9965d6e2c6b36bda6de @txus committed Oct 1, 2011
Showing with 40 additions and 14 deletions.
  1. +4 −4 src/micetrap.c
  2. +3 −8 src/server.c
  3. +32 −2 src/service.c
  4. +1 −0 src/service.h
View
@@ -7,16 +7,16 @@
int main(int argc, char *argv[])
{
- /* if (argc < 2) die("USAGE: micetrap <service> <port>"); */
+ if (argc < 2) die("USAGE: micetrap <service> <port>");
int port = 0;
if (argc == 3) {
port = atoi(argv[2]);
}
- /* Service *service = Service_build(argv[1]); */
- Service *service = Service_build("ftp");
+ Service *service = Service_build(argv[1]);
+ /* Service *service = Service_build("ftp"); */
- Server_start(service, 9999);
+ Server_start(service, port);
return 0;
}
View
@@ -35,13 +35,8 @@ void Server_start(Service *service, int port)
int received = 0;
- char *response;
- int response_length = 0;
-
- response = Service_random_response(service);
- printf("Response is going to be %s.", response);
- response_length = strlen(response);
-
+ char *response = Service_random_response(service);
+ int response_length = strlen(response);
// Declare server and client addresses
struct sockaddr_in server, client;
@@ -65,7 +60,7 @@ void Server_start(Service *service, int port)
die("Could not bind the socket.");
}
- printf("Server ready and listening on port %d...", port);
+ printf("Fake %s server ready and listening on port %d...\n", service->name, port);
listen(listen_fd, 5);
while(1) {
View
@@ -32,8 +32,38 @@ Service *Service_build(const char *name)
service->responses = responses;
service->response_count = 1;
+ } else if (strcmp(name, "mysql") == 0) {
+ int ports[] = {3306};
+ service->ports = ports;
+
+ char *responses[] = {
+ ".\0\0\0\n4.0.13\0...\0"
+ };
+ service->responses = responses;
+ service->response_count = 1;
+
+ } else if (strcmp(name, "samba") == 0) {
+ int ports[] = {135, 139, 445};
+ service->ports = ports;
+
+ char *responses[] = {
+ "smbd: error while loading shared libraries: libattr.so.1: cannot open shared object file: No such file or directory\n",
+ };
+ service->responses = responses;
+ service->response_count = 1;
+
+ } else if (strcmp(name, "torrent") == 0) {
+ int ports[] = {9888};
+ service->ports = ports;
+
+ char *responses[] = {
+ "\x13 BitTorrent protocol\0\0\0\0\0\0\0\0"
+ };
+ service->responses = responses;
+ service->response_count = 1;
+
} else {
- die("Unrecognized service name.");
+ die("Unrecognized service name. Services available are: ftp, http, mysql, samba, torrent");
}
service->name = strdup(name);
@@ -59,5 +89,5 @@ char *Service_random_response(Service *service)
int idx = rand() % service->response_count;
- return *service->responses[idx];
+ return service->responses[idx];
}
View
@@ -12,5 +12,6 @@ typedef struct Service Service;
Service *Service_build(const char *name);
int Service_random_port(Service *service);
+char *Service_random_response(Service *service);
#endif

0 comments on commit 36da7a4

Please sign in to comment.