123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /**
- * CycriptLoader
- *
- * Load cycript!
- *
- * By Sam Binger and Kevin Bradley
- *
- */
- /**
- This dylib injects into our target process, iterates through which port is available and then posts a distributed notification that our cycripter binary is waiting to hear back
- and starts listening with CYListenServer on the specified port. After cycripter echoes out the command the user can succesfully connect to cycript and control the injected process.
- */
- #import <Foundation/Foundation.h>
- #import "Cycript.h"
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- @interface NSDistributedNotificationCenter : NSNotificationCenter
- + (id)defaultCenter;
- - (void)addObserver:(id)arg1 selector:(SEL)arg2 name:(id)arg3 object:(id)arg4;
- - (void)postNotificationName:(id)arg1 object:(id)arg2 userInfo:(id)arg3;
- @end
- %ctor
- {
- //check to see if 1337 is available
- int sock = socket(AF_INET, SOCK_STREAM, 0);
- if(sock < 0) {
- NSLog(@"#### cycript runner: socket error\n");
- return;
- }
- printf("Opened %d\n", sock);
- in_port_t port = 1337;
- struct sockaddr_in serv_addr;
- bzero((char *) &serv_addr, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = INADDR_ANY;
- serv_addr.sin_port = port;
- BOOL usablePort = FALSE;
-
- while(usablePort != TRUE){
- if (bind(sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
- if(errno == EADDRINUSE) {
- NSLog(@"#### cycript runner: the port is not available: %hu already to other process\n", port);
- port++;
- serv_addr.sin_port = port;
- continue;
- } else {
- NSLog(@"#### cycript runner: could not bind to process (%d) %s\n", errno, strerror(errno));
- break;
- //return;
- }
- } else {
-
- usablePort = TRUE;
- NSLog(@"#### cycript runner: success with port %i\n", port);
-
- }
-
- }
-
-
-
- socklen_t len = sizeof(serv_addr);
- if (getsockname(sock, (struct sockaddr *)&serv_addr, &len) == -1) {
- perror("getsockname");
- //return;
- }
- //int port = ntohs(serv_addr.sin_port);
- NSLog(@"#### cycript runner: port number %d\n", port);
- NSString *portNumber = [NSString stringWithFormat:@"%d", port];
- [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"cycriptPortAvailable" object:nil userInfo:@{@"port": portNumber}];
-
-
- /*
- if (close (sock) < 0 ) {
- NSLog(@"#### cycript runner: did not close: %s\n", strerror(errno));
- // return;
- }
- */
- CYListenServer(port);
- NSLog(@"running server on port: %d", port);
- }
|