GDBusProxy *gatt_select_attribute(const char *path) { GDBusProxy *proxy; proxy = select_proxy(path, services); if (proxy) return proxy; proxy = select_proxy(path, characteristics); if (proxy) return proxy; return select_proxy(path, descriptors); }
int connect_proxy_chain( int sock, unsigned int target_ip, unsigned short target_port, proxy_data *pd, unsigned int proxy_count, chain_type ct, int max_chain ) { proxy_data p4; proxy_data *p1,*p2,*p3; int ns=-1; int offset=0; int alive_count=0; int curr_len=0; #define TP "<>" #define DT "|D-chain|" #define ST "|S-chain|" #define RT "|R-chain|" p3=&p4; again: switch(ct) { case DYNAMIC_TYPE: alive_count=calc_alive(pd,proxy_count); offset=0; do { if(!(p1=select_proxy(FIFOLY,pd,proxy_count,&offset))) goto error_more; } while(SUCCESS!=start_chain(&ns,p1,DT) && offset<proxy_count); for(;;) { p2=select_proxy(FIFOLY,pd,proxy_count,&offset); if(!p2) break; if(SUCCESS!=chain_step(ns,p1,p2)) goto again; p1=p2; } proxychains_write_log(TP); p3->ip=target_ip; p3->port=target_port; if(SUCCESS!=chain_step(ns,p1,p3)) goto error; break; case STRICT_TYPE: alive_count=calc_alive(pd,proxy_count); offset=0; if(!(p1=select_proxy(FIFOLY,pd,proxy_count,&offset))) goto error_strict; if(SUCCESS!=start_chain(&ns,p1,ST)) goto error_strict; while(offset<proxy_count) { if(!(p2=select_proxy(FIFOLY,pd,proxy_count,&offset))) break; if(SUCCESS!=chain_step(ns,p1,p2)) goto error_strict; p1=p2; } proxychains_write_log(TP); p3->ip=target_ip; p3->port=target_port; if(SUCCESS!=chain_step(ns,p1,p3)) goto error; break; case RANDOM_TYPE: alive_count=calc_alive(pd,proxy_count); if(alive_count<max_chain) goto error_more; curr_len=offset=0; do { if(!(p1=select_proxy(RANDOMLY,pd,proxy_count,&offset))) goto error_more; } while(SUCCESS!=start_chain(&ns,p1,RT) && offset<max_chain); while(++curr_len<max_chain) { if(!(p2=select_proxy(RANDOMLY,pd,proxy_count,&offset))) goto error_more; if(SUCCESS!=chain_step(ns,p1,p2)) goto again; p1=p2; } proxychains_write_log(TP); p3->ip=target_ip; p3->port=target_port; if(SUCCESS!=chain_step(ns,p1,p3)) goto error; } done: proxychains_write_log("<><>-OK\n"); dup2(ns,sock); close(ns); return 0; error: if(ns!=-1) close(ns); errno = ECONNREFUSED; // for nmap ;) return -1; error_more: proxychains_write_log("\n!!!need more proxies!!!\n"); error_strict: release_all(pd,proxy_count); if(ns!=-1) close(ns); errno = ETIMEDOUT; return -1; }
int connect_proxy_chain(int sock, ip_type target_ip, unsigned short target_port, proxy_data * pd, unsigned int proxy_count, chain_type ct, unsigned int max_chain) { proxy_data p4; proxy_data *p1, *p2, *p3; int ns = -1; int rc = -1; unsigned int offset = 0; unsigned int alive_count = 0; unsigned int curr_len = 0; unsigned int curr_pos = 0; unsigned int looped = 0; // went back to start of list in RR mode p3 = &p4; PFUNC(); again: rc = -1; DUMP_PROXY_CHAIN(pd, proxy_count); switch (ct) { case DYNAMIC_TYPE: alive_count = calc_alive(pd, proxy_count); offset = 0; do { if(!(p1 = select_proxy(FIFOLY, pd, proxy_count, &offset))) goto error_more; } while(SUCCESS != start_chain(&ns, p1, DT) && offset < proxy_count); for(;;) { p2 = select_proxy(FIFOLY, pd, proxy_count, &offset); if(!p2) break; if(SUCCESS != chain_step(ns, p1, p2)) { PDEBUG("GOTO AGAIN 1\n"); goto again; } p1 = p2; } //proxychains_write_log(TP); p3->ip = target_ip; p3->port = target_port; if(SUCCESS != chain_step(ns, p1, p3)) goto error; break; case ROUND_ROBIN_TYPE: alive_count = calc_alive(pd, proxy_count); curr_pos = offset = proxychains_proxy_offset; if(alive_count < max_chain) goto error_more; PDEBUG("1:rr_offset = %d, curr_pos = %d\n", offset, curr_pos); /* Check from current RR offset til end */ for (;rc != SUCCESS;) { if (!(p1 = select_proxy(FIFOLY, pd, proxy_count, &offset))) { /* We've reached the end of the list, go to the start */ offset = 0; looped++; continue; } else if (looped && rc > 0 && offset >= curr_pos) { PDEBUG("GOTO MORE PROXIES 0\n"); /* We've gone back to the start and now past our starting position */ proxychains_proxy_offset = 0; goto error_more; } PDEBUG("2:rr_offset = %d\n", offset); rc=start_chain(&ns, p1, RRT); } /* Create rest of chain using RR */ for(curr_len = 1; curr_len < max_chain;) { PDEBUG("3:rr_offset = %d, curr_len = %d, max_chain = %d\n", offset, curr_len, max_chain); p2 = select_proxy(FIFOLY, pd, proxy_count, &offset); if(!p2) { /* Try from the beginning to where we started */ offset = 0; continue; } else if(SUCCESS != chain_step(ns, p1, p2)) { PDEBUG("GOTO AGAIN 1\n"); goto again; } else p1 = p2; curr_len++; } //proxychains_write_log(TP); p3->ip = target_ip; p3->port = target_port; proxychains_proxy_offset = offset+1; PDEBUG("pd_offset = %d, curr_len = %d\n", proxychains_proxy_offset, curr_len); if(SUCCESS != chain_step(ns, p1, p3)) goto error; break; case STRICT_TYPE: alive_count = calc_alive(pd, proxy_count); offset = 0; if(!(p1 = select_proxy(FIFOLY, pd, proxy_count, &offset))) { PDEBUG("select_proxy failed\n"); goto error_strict; } if(SUCCESS != start_chain(&ns, p1, ST)) { PDEBUG("start_chain failed\n"); goto error_strict; } while(offset < proxy_count) { if(!(p2 = select_proxy(FIFOLY, pd, proxy_count, &offset))) break; if(SUCCESS != chain_step(ns, p1, p2)) { PDEBUG("chain_step failed\n"); goto error_strict; } p1 = p2; } //proxychains_write_log(TP); p3->ip = target_ip; p3->port = target_port; if(SUCCESS != chain_step(ns, p1, p3)) goto error; break; case RANDOM_TYPE: alive_count = calc_alive(pd, proxy_count); if(alive_count < max_chain) goto error_more; curr_len = offset = 0; do { if(!(p1 = select_proxy(RANDOMLY, pd, proxy_count, &offset))) goto error_more; } while(SUCCESS != start_chain(&ns, p1, RT) && offset < max_chain); while(++curr_len < max_chain) { if(!(p2 = select_proxy(RANDOMLY, pd, proxy_count, &offset))) goto error_more; if(SUCCESS != chain_step(ns, p1, p2)) { PDEBUG("GOTO AGAIN 2\n"); goto again; } p1 = p2; } //proxychains_write_log(TP); p3->ip = target_ip; p3->port = target_port; if(SUCCESS != chain_step(ns, p1, p3)) goto error; } proxychains_write_log(TP " OK\n"); dup2(ns, sock); close(ns); return 0; error: if(ns != -1) close(ns); errno = ECONNREFUSED; // for nmap ;) return -1; error_more: proxychains_write_log("\n!!!need more proxies!!!\n"); error_strict: PDEBUG("error\n"); release_all(pd, proxy_count); if(ns != -1) close(ns); errno = ETIMEDOUT; return -1; }
int connect_proxy_chain(int sock, ip_type target_ip, unsigned short target_port, proxy_data * pd, unsigned int proxy_count, chain_type ct, unsigned int max_chain) { proxy_data p4; proxy_data *p1, *p2, *p3; int ns = -1; unsigned int offset = 0; unsigned int alive_count = 0; unsigned int curr_len = 0; p3 = &p4; PDEBUG("connect_proxy_chain\n"); again: switch (ct) { case DYNAMIC_TYPE: calc_alive(pd, proxy_count); offset = 0; do { if(!(p1 = select_proxy(FIFOLY, pd, proxy_count, &offset))) goto error_more; } while(SUCCESS != start_chain(&ns, p1, DT) && offset < proxy_count); for(;;) { p2 = select_proxy(FIFOLY, pd, proxy_count, &offset); if(!p2) break; if(SUCCESS != chain_step(ns, p1, p2)) { PDEBUG("GOTO AGAIN 1\n"); goto again; } p1 = p2; } //proxychains_write_log(TP); p3->ip = target_ip; p3->port = target_port; if(SUCCESS != chain_step(ns, p1, p3)) goto error; break; /* Chain mirrors order it appears in config file and each * proxy chain must be online. */ case STRICT_TYPE: /* Counts the number of proxy entries that are in the * PLAY_STATE. */ calc_alive(pd, proxy_count); offset = 0; /* In this case, select_proxy will choose the next avilable * proxy that is in the PLAY_STATE. */ if(!(p1 = select_proxy(FIFOLY, pd, proxy_count, &offset))) { PDEBUG("select_proxy failed\n"); goto error_strict; } /* Connect to the first proxy server in the chain. */ if(SUCCESS != start_chain(&ns, p1, ST)) { PDEBUG("start_chain failed\n"); goto error_strict; } while(offset < proxy_count) { if(!(p2 = select_proxy(FIFOLY, pd, proxy_count, &offset))) break; if(SUCCESS != chain_step(ns, p1, p2)) { PDEBUG("chain_step failed\n"); goto error_strict; } p1 = p2; } //proxychains_write_log(TP); p3->ip = target_ip; p3->port = target_port; if(SUCCESS != chain_step(ns, p1, p3)) goto error; break; case RANDOM_TYPE: alive_count = calc_alive(pd, proxy_count); if(alive_count < max_chain) goto error_more; curr_len = offset = 0; do { if(!(p1 = select_proxy(RANDOMLY, pd, proxy_count, &offset))) goto error_more; } while(SUCCESS != start_chain(&ns, p1, RT) && offset < max_chain); while(++curr_len < max_chain) { if(!(p2 = select_proxy(RANDOMLY, pd, proxy_count, &offset))) goto error_more; if(SUCCESS != chain_step(ns, p1, p2)) { PDEBUG("GOTO AGAIN 2\n"); goto again; } p1 = p2; } //proxychains_write_log(TP); p3->ip = target_ip; p3->port = target_port; if(SUCCESS != chain_step(ns, p1, p3)) goto error; } proxychains_write_log(TP " OK\n"); dup2(ns, sock); close(ns); return 0; error: if(ns != -1) close(ns); errno = ECONNREFUSED; // for nmap ;) return -1; error_more: proxychains_write_log("\n!!!need more proxies!!!\n"); error_strict: PDEBUG("error\n"); release_all(pd, proxy_count); if(ns != -1) close(ns); errno = ETIMEDOUT; return -1; }