def wapper_httpsend(data, resent_ip, count): if (send_filter.filter(data)): uri = data['uri'] data_headers = None if (data.has_key('headers')): data_headers = data['headers'] send_log.log_debug("request headers %s" % data_headers) port = data["port"] url = "http://%s:%s%s" % (resent_ip, port, uri) send_log.log_info("request url %s" % url) request = None # add body if (cmp(data['method'], "GET") == 0): request = urllib2.Request(url) elif (cmp(data['method'], "POST") == 0): get_body = data['body'] message = "request body %s" % get_body send_log.log_debug(message) request = urllib2.Request(url, str(get_body)) # add header if (request and data_headers): for key, value in data_headers.iteritems(): request.add_header(key, value) if (request): for i in range(int(count)): send_request(request)
def send_request(request): try: response = urllib2.urlopen(request) code = response.getcode() send_log.log_debug("response code %s" % code) if (code == 302): redirect_url = response.geturl() send_log.log_info("redirect to %s" % redirect_url) redirect_request = urllib2.Request(redirect_url) response = urllib2.urlopen(redirect_request) #print code except Exception, e: error_str = "send request exception ,%s" % e send_log.log_error(error_str) pass
def main_pcap(p_time, p_data, local_ip, port, resent_ip, count): p = dpkt.ethernet.Ethernet(p_data) if p.type == dpkt.ethernet.ETH_TYPE_IP: ip_data = p.data src_ip = '%d.%d.%d.%d' % tuple(map(ord, list(ip_data.src))) dst_ip = '%d.%d.%d.%d' % tuple(map(ord, list(ip_data.dst))) if ip_data.p == dpkt.ip.IP_PROTO_UDP: udp_data = p.data.data if udp_data.data: try: send_log.log_info("get data: %s" % udp_data.data) data = eval(udp_data.data) httpsend.wapper_httpsend(data, resent_ip, count) except Exception, e: error_str = "Capture src_ip %s:local_ip %s:dst_ip %s:exception: %s" % ( src_ip, local_ip, dst_ip, e) send_log.log_error(error_str) pass
def start(): if (len(sys.argv) < 3): capture_nc = send_config.getConfig("config", 'nc') if (not capture_nc): print "error not have network card info" send_log.log_error("error not have network card info") sys.exit(1) resent_ip = send_config.getConfig("config", 'resent_ip') if (not resent_ip): print "error not have resent ip info" send_log.log_error("error not have resent ip info") sys.exit(1) print "Start sender sever network card: %s resent ip: %s" % ( capture_nc, resent_ip) send_log.log_info("Start sender sever network card: %s resent ip: %s" % (capture_nc, resent_ip)) count = send_config.getConfig("config", 'count') port = send_config.getConfig("config", 'port') if (count): if (port): capture_udp.capture(capture_nc, resent_ip, count, int(port)) else: capture_udp.capture(capture_nc, resent_ip, count) else: capture_udp.capture(capture_nc, resent_ip) else: capture_nc = sys.argv[1] resent_ip = sys.argv[2] print "Start sender sever network card: %s resent ip: %s" % ( capture_nc, resent_ip) if (len(sys.argv) == 4): count = sys.argv[3] capture_udp.capture(capture_nc, resent_ip, count) elif (len(sys.argv) == 5): count = sys.argv[3] port = sys.argv[4] capture_udp.capture(capture_nc, resent_ip, count, port) else: capture_udp.capture(capture_nc, resent_ip)