in code/utility/generate_waf_logs.py [0:0]
def source_ip_calculate(ipName, country = "", labels = []):
#print ("SIC")
#print (ipName)
#print (country)
#print (labels)
if country == "":
##print ('picking random country')
country = random.choice(list(ipTable.keys()))
##print (country)
if ipName == 'user':
cidrList = ipTable[country.upper()]
c = len(cidrList)
##print ("c: " + str(c))
if c == 1:
x = 0
else:
x = random.randrange(0,c)
##print ("x: " + str(x))
##print (cidrList[x])
##print (cidrList[x]['Start'])
##print (cidrList[x]['End'])
s = int.from_bytes(socket.inet_aton(cidrList[x]['Start']),'big')
e = int.from_bytes(socket.inet_aton(cidrList[x]['End']),'big')
ip = socket.inet_ntoa(struct.pack('>I', random.randint(s,e)))
response = {
"sourceip": ip,
"country": country
}
response['labels'] = labels
return (response)
elif ipName == 'anonymousBadBot':
cidrList = badBotCIDRRanges[country]
c = len(cidrList)
if c == 1:
x = 0
else:
x = random.randrange(0,c)
##print ("x: " + str(x))
##print (cidrList[x])
##print (cidrList[x]['Start'])
##print (cidrList[x]['End'])
s = int.from_bytes(socket.inet_aton(cidrList[x]['Start']),'big')
e = int.from_bytes(socket.inet_aton(cidrList[x]['End']),'big')
ip = socket.inet_ntoa(struct.pack('>I', random.randint(s,e)))
response = {
"sourceip": ip,
"country": country
}
response['labels'] = labels
response['labels'].append({'name':'awswaf:managed:aws:anonymous-ip-list:HostingProviderIPList'})
return (response)
elif ipName == 'knownbotdatacenter':
cidrList = badBotCIDRRanges[country]
c = len(cidrList)
if c == 1:
x = 0
else:
x = random.randrange(0,c)
##print ("x: " + str(x))
##print (cidrList[x])
##print (cidrList[x]['Start'])
##print (cidrList[x]['End'])
s = int.from_bytes(socket.inet_aton(cidrList[x]['Start']),'big')
e = int.from_bytes(socket.inet_aton(cidrList[x]['End']),'big')
ip = socket.inet_ntoa(struct.pack('>I', random.randint(s,e)))
response = {
"sourceip": ip,
"country": country
}
response['labels'] = labels
return (response)
elif ipName == 'okBot':
cidrList = okBotCIDRRanges[country]
c = len(cidrList)
if c == 1:
x = 0
else:
x = random.randrange(0,c)
##print ("x: " + str(x))
##print (cidrList[x])
##print (cidrList[x]['Start'])
##print (cidrList[x]['End'])
s = int.from_bytes(socket.inet_aton(cidrList[x]['Start']),'big')
e = int.from_bytes(socket.inet_aton(cidrList[x]['End']),'big')
ip = socket.inet_ntoa(struct.pack('>I', random.randint(s,e)))
response = {
"sourceip": ip,
"country": country
}
response['labels'] = labels
return (response)