/** \ingroup Core_Print \param type \param skey */ void ops_print_secret_key_verbose(const ops_content_tag_t type, const ops_secret_key_t* skey) { printf("------- SECRET KEY or ENCRYPTED SECRET KEY ------\n"); if(type == OPS_PTAG_CT_SECRET_KEY) print_tagname("SECRET_KEY"); else print_tagname("ENCRYPTED_SECRET_KEY"); // ops_print_public_key(key); printf("S2K Usage: %d\n",skey->s2k_usage); if(skey->s2k_usage != OPS_S2KU_NONE) { printf("S2K Specifier: %d\n",skey->s2k_specifier); printf("Symmetric algorithm: %d (%s)\n",skey->algorithm, ops_show_symmetric_algorithm(skey->algorithm)); printf("Hash algorithm: %d (%s)\n",skey->hash_algorithm, ops_show_hash_algorithm(skey->hash_algorithm)); if(skey->s2k_specifier != OPS_S2KS_SIMPLE) print_hexdump("Salt",skey->salt,sizeof skey->salt); if(skey->s2k_specifier == OPS_S2KS_ITERATED_AND_SALTED) printf("Octet count: %d\n",skey->octet_count); print_hexdump("IV",skey->iv,ops_block_size(skey->algorithm)); } /* no more set if encrypted */ if(type == OPS_PTAG_CT_ENCRYPTED_SECRET_KEY) return; switch(skey->public_key.algorithm) { case OPS_PKA_RSA: print_bn("d",skey->key.rsa.d); print_bn("p",skey->key.rsa.p); print_bn("q",skey->key.rsa.q); print_bn("u",skey->key.rsa.u); break; case OPS_PKA_DSA: print_bn("x",skey->key.dsa.x); break; default: assert(0); } if(skey->s2k_usage == OPS_S2KU_ENCRYPTED_AND_HASHED) print_hexdump("Checkhash",skey->checkhash,OPS_CHECKHASH_SIZE); else printf("Checksum: %04x\n",skey->checksum); printf("------- end of SECRET KEY or ENCRYPTED SECRET KEY ------\n"); }
int main(int argc, char** argv){ char buf[BUFLEN]; char *dev = calloc(10, 1); struct netdev netdev; CLEAR(buf); tun_init(dev); netdev_init(&netdev, "10.0.0.4", "00:0c:29:6d:50:25"); arp_init(); while(1) { if (tun_read(buf, BUFLEN) < 0) { print_error("ERR: Read from tun_fd: %s\n", strerror(errno)); } print_hexdump(buf, BUFLEN); struct eth_hdr *hdr = init_eth_hdr(buf); handle_frame(&netdev, hdr); } }
void print_log_hexdump(const char *data, int len, const char *fmt, ...) { time_t t; struct tm tm; va_list ap; /* XXX Worry about speed later */ t = time(NULL); localtime_r(&t, &tm); printf("[%04d/%02d/%02d-%02d:%02d:%02d] ", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); printf("\ndata=%p len=%d\n", data, len); print_hexdump(data, len); }
void make_tunnel(int rsock, const char *remote) { char buf[4096], *outbuf = NULL, *inbuf = NULL; int sock = -1, outlen = 0, inlen = 0; struct sockaddr *sa = NULL; const char *source; if (map_list) { if (!(source = map_find(remote))) { debug("<%d> connection from unmapped address (%s), disconnecting\n", rsock, remote); goto cleanup; } debug("<%d> mapped to %s\n", rsock, source); } else source = source_host; if (ircpass) { int i, ret; for (i = 0; i < sizeof(buf) - 1; i++) { if ((ret = read(rsock, buf + i, 1)) < 1) goto cleanup; if (buf[i] == '\n') break; } buf[i] = 0; if (i > 0 && buf[i - 1] == '\r') buf[i - 1] = 0; if (i == 4095 || strncasecmp(buf, "PASS ", 5)) { char *tmp; debug("<%d> irc proxy auth failed - junk\n", rsock); tmp = "ERROR :Closing link: Make your client send password first\r\n"; if (write(rsock, tmp, strlen(tmp)) != strlen(tmp)) { // Do nothing. We're failing anyway. } goto cleanup; } if (strcmp(buf + 5, ircpass)) { char *tmp; debug("<%d> irc proxy auth failed - password incorrect\n", rsock); tmp = ":6tunnel 464 * :Password incorrect\r\nERROR :Closing link: Password incorrect\r\n"; if (write(rsock, tmp, strlen(tmp)) != strlen(tmp)) { // Do nothing. We're failing anyway. } goto cleanup; } debug("<%d> irc proxy auth succeded\n", rsock); } if (!(sa = resolve_host(remote_host, remote_hint))) { debug("<%d> unable to resolve %s\n", rsock, remote_host); goto cleanup; } if ((sock = socket(sa->sa_family, SOCK_STREAM, 0)) == -1) { debug("<%d> unable to create socket (%s)\n", rsock, strerror(errno)); goto cleanup; } free(sa); sa = NULL; if (source) { if (!(sa = resolve_host(source, local_hint))) { debug("<%d> unable to resolve source host (%s)\n", rsock, source); goto cleanup; } if (bind(sock, sa, (local_hint == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))) { debug("<%d> unable to bind to source host (%s)\n", rsock, source); goto cleanup; } free(sa); sa = NULL; } sa = resolve_host(remote_host, remote_hint); ((struct sockaddr_in*) sa)->sin_port = htons(remote_port); if (connect(sock, sa, (sa->sa_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))) { debug("<%d> connection refused (%s,%d)\n", rsock, remote_host, remote_port); goto cleanup; } free(sa); sa = NULL; debug("<%d> connected to %s,%d\n", rsock, remote_host, remote_port); if (ircsendpass) { snprintf(buf, 4096, "PASS %s\r\n", ircsendpass); if (write(sock, buf, strlen(buf)) != strlen(buf)) goto cleanup; } for (;;) { fd_set rds, wds; int ret, sent; FD_ZERO(&rds); FD_SET(sock, &rds); FD_SET(rsock, &rds); FD_ZERO(&wds); if (outbuf && outlen) FD_SET(rsock, &wds); if (inbuf && inlen) FD_SET(sock, &wds); ret = select((sock > rsock) ? (sock + 1) : (rsock + 1), &rds, &wds, NULL, NULL); if (FD_ISSET(rsock, &wds)) { sent = write(rsock, outbuf, outlen); if (sent < 1) goto cleanup; if (sent == outlen) { free(outbuf); outbuf = NULL; outlen = 0; } else { memmove(outbuf, outbuf + sent, outlen - sent); outlen -= sent; } } if (FD_ISSET(sock, &wds)) { sent = write(sock, inbuf, inlen); if (sent < 1) goto cleanup; if (sent == inlen) { free(inbuf); inbuf = NULL; inlen = 0; } else { memmove(inbuf, inbuf + sent, inlen - sent); inlen -= sent; } } if (FD_ISSET(sock, &rds)) { if ((ret = read(sock, buf, 4096)) < 1) goto cleanup; if (hexdump) { printf("<%d> recvfrom %s,%d\n", rsock, remote_host, remote_port); print_hexdump(buf, ret); } sent = write(rsock, buf, ret); if (sent < 1) goto cleanup; if (sent < ret) { outbuf = xrealloc(outbuf, outlen + ret - sent); memcpy(outbuf + outlen, buf + sent, ret - sent); outlen = ret - sent; } } if (FD_ISSET(rsock, &rds)) { if ((ret = read(rsock, buf, 4096)) < 1) goto cleanup; if (hexdump) { printf("<%d> sendto %s,%d\n", rsock, remote_host, remote_port); print_hexdump(buf, ret); } sent = write(sock, buf, ret); if (sent < 1) goto cleanup; if (sent < ret) { inbuf = xrealloc(inbuf, inlen + ret - sent); memcpy(inbuf + inlen, buf + sent, ret - sent); inlen = ret - sent; } } } cleanup: if (sa) free(sa); close(rsock); if (sock != -1) close(sock); }
static void print_data(const char *name,const ops_data_t *data) { print_hexdump(name,data->contents,data->len); }
/** * eg_inject main * * @param[in] argc arguments count * @param[in] argv arguments value */ int eg_inject_main(int argc, char *argv[]) { static char buf[2000]; unsigned long sendflags = 0; char *ifname = NULL; char *infile = NULL; int filetype = EG_FILETYPE_PCAP; int interval = 0; int qflag = 0; int c; FILE *in; pktif_t out; int len; struct timeval tv; while ((c = getopt(argc, argv, "cw:t:r:i:qh?")) != -1) { switch (c) { case 'c': fprintf(stderr, "warning: -c option has been deprecated.\n"); sendflags |= PKT_SEND_FLAG_COMPLETE; break; case 'w': interval = atoi(optarg); break; case 't': if (strncasecmp("PCAP", optarg, strlen(optarg)) == 0) { filetype = EG_FILETYPE_PCAP; } else if (strncasecmp("RAW", optarg, strlen(optarg)) == 0) { filetype = EG_FILETYPE_RAW; } else { fprintf(stderr, "invalid file type: %s\n", optarg); usage(); exit(EXIT_SUCCESS); } break; case 'r': infile = optarg; break; case 'i': ifname = optarg; break; case 'q': qflag = 1; break; case 'h': case '?': usage(); exit(EXIT_SUCCESS); default: usage(); exit(EXIT_FAILURE); } } if (ifname == NULL) { usage(); exit(EXIT_FAILURE); } if (infile != NULL) { in = fopen(infile, "r"); if (!in) { fprintf(stderr, "Failed to open: %s\n", infile); } } else { in = stdin; } out = pkthandler.open_send(ifname, sendflags); if (filetype == EG_FILETYPE_PCAP) { while (pkt_pcap_read(in, buf, sizeof(buf), &len, NULL, &tv) > 0) { pkthandler.send(out, buf, len); if (!qflag) { printf("\n---> %d bytes to %s\n", len, ifname); print_hexdump(buf, len); } if (interval) { usleep(interval * 1000); } } } else { while ((len = fread(buf, 1, sizeof(buf), in)) > 0) { pkthandler.send(out, buf, len); if (!qflag) { printf("\n---> %d bytes to %s\n", len, ifname); print_hexdump(buf, len); } if (interval) { usleep(interval * 1000); } } } exit(EXIT_SUCCESS); }