summaryrefslogtreecommitdiffstats
path: root/census
diff options
context:
space:
mode:
authorChinaman <root@chinaman>2011-09-06 19:47:58 +0200
committerChinaman <root@chinaman>2011-09-06 19:47:58 +0200
commit108f3616e3f4958752d881192ef29e5fc4c2b045 (patch)
tree3c67478c852265219b72e6e1b05467d7065b7ba8 /census
parentb2d65500160bcdf7abb2bf985f7da582b810e25c (diff)
parentc3bc5a6d16868c121aca780f3109155797b51d76 (diff)
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'census')
-rw-r--r--census/Makefile6
-rw-r--r--census/README.md13
-rw-r--r--census/TODO.md3
-rw-r--r--census/VERSION1
-rwxr-xr-xcensus/arping.py35
-rwxr-xr-xcensus/arping_users.py71
-rw-r--r--census/mac_names.lst14
7 files changed, 143 insertions, 0 deletions
diff --git a/census/Makefile b/census/Makefile
new file mode 100644
index 00000000..2c6c1c03
--- /dev/null
+++ b/census/Makefile
@@ -0,0 +1,6 @@
+.phony: all
+
+all: arping.py arping_users.py
+ echo "call python ./arping_users.py v"
+install:
+ apt-get install python-scapy
diff --git a/census/README.md b/census/README.md
new file mode 100644
index 00000000..e45d39c1
--- /dev/null
+++ b/census/README.md
@@ -0,0 +1,13 @@
+ARPING Users
+==========
+
+This is a simplified python script which checks the available subnet for computers online and returns a list of users which are online based on their mac-address
+
+
+arping_users.py:
+ call `python arping_users.py v` for verbose output -> print all discovered hosts
+
+SNMPWALK Command
+===============
+
+snmpwalk -c shammunity 10.42.0.1 1.3.6.1.2.1.3.1.1.2
diff --git a/census/TODO.md b/census/TODO.md
new file mode 100644
index 00000000..daacfd58
--- /dev/null
+++ b/census/TODO.md
@@ -0,0 +1,3 @@
+BUGS
+=====
+
diff --git a/census/VERSION b/census/VERSION
new file mode 100644
index 00000000..6c50e659
--- /dev/null
+++ b/census/VERSION
@@ -0,0 +1 @@
++++++++[>+++++++>+++++++<<-]>.>---.<-.
diff --git a/census/arping.py b/census/arping.py
new file mode 100755
index 00000000..3245f1ee
--- /dev/null
+++ b/census/arping.py
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+
+import logging
+log = logging.getLogger('arpingy')
+logging.disable(logging.WARNING)
+
+import os,sys
+try:
+ if (os.geteuid() != 0):
+ raise Exception('no root permissions')
+ from scapy.all import * #might throws "no such module"
+
+ def arpingy(iprange="10.42.1.0/24",iface='eth0'):
+ log.debug("pinging "+ str(iprange))
+ """Arping function takes IP Address or Network, returns nested mac/ip list"""
+ try:
+ conf.verb=0
+ ans,unans=arping(iprange,iface=iface,timeout=1,retry=3)
+
+ collection = []
+ for snd, rcv in ans:
+ result = rcv.sprintf(r"%ARP.psrc% %Ether.src%").split()
+ log.debug(result)
+ return result # take just the first arp reply
+ except Exception as e:
+ print ("something went wrong while arpinging " + str(e))
+ return []
+
+except Exception as e:
+ raise Exception("Cannot load arping functions!" + str(e))
+
+
+if __name__ =='__main__':
+ logging.basicConfig(level=logging.DEBUG)
+ arpingy(sys.argv[1],sys.argv[2])
diff --git a/census/arping_users.py b/census/arping_users.py
new file mode 100755
index 00000000..f0df4924
--- /dev/null
+++ b/census/arping_users.py
@@ -0,0 +1,71 @@
+#!/usr/bin/python
+import subprocess,re,logging,sys
+
+from arping import arpingy
+from multiprocessing import Pool
+logging.basicConfig(level=logging.DEBUG)
+log = logging.getLogger("main")
+DEV='eth0'
+MAC_NAMES='mac_names.lst'
+data = []
+my_addr = False
+my_names = {}
+ret = {}
+quiet=False
+
+if len(sys.argv) > 1 and sys.argv[1] == 'q':
+ quiet=True
+def get_own_addr():
+ data = subprocess.Popen(['/sbin/ifconfig',DEV],
+ stdout=subprocess.PIPE).communicate()[0].replace('\n','')
+ return re.sub(r'.*HWaddr ([0-9A-Fa-f:]*).*inet addr:([0-9.]*).*' ,
+ r'\1 \2',data).split()
+
+def load_names(mac_file):
+ names = {}
+ f = open(mac_file)
+ for l in f:
+ mac,name = l.split(' ',1)
+ names[mac] = name.replace('\n','')
+ f.close()
+ return names
+def print_config():
+ log.info("My Addr : %s" %str(my_addr))
+ log.info("MAC Names file: %s " %MAC_NAMES)
+ log.debug("Loaded names : ")
+ for mac,name in my_names.iteritems():
+ log.debug("%s => %s" %(mac,name))
+def init():
+ my_addr = get_own_addr()
+ my_names = load_names(MAC_NAMES)
+
+def main():
+ init()
+ print_config()
+ exit(0)
+ def arping_helper(dic):
+ return arpingy(**dic)
+
+for first in range(1,4):
+ for second in range(256):
+ data.append({'iprange':'10.42.'+str(first)+'.'+str(second),'iface':DEV})
+
+ try:
+ p = Pool(20)
+ ret = filter(lambda x:x , p.map(arping_helper, data))
+ myip,mymac = get_own_addr()
+ ret.append([mymac,myip])
+ p.terminate()
+ except Exception as e:
+ print 'you fail '+str(e)
+
+
+
+ for p in ret:
+ if not quiet:
+ print p[0] + " => " + p[1]
+ if p[1] in names:
+ print names[p[1]]+ " is online"
+if __name__ == "__main__":
+ log.debug("starting arping_users")
+ main()
diff --git a/census/mac_names.lst b/census/mac_names.lst
new file mode 100644
index 00000000..85fbfb25
--- /dev/null
+++ b/census/mac_names.lst
@@ -0,0 +1,14 @@
+00:40:63:c8:b5:a0 krebs
+00:23:54:29:1d:3e hadez
+00:26:c7:bd:a7:1a Martin
+04:1e:64:05:39:28 Stephan
+5c:59:48:22:2d:d2 Phil
+00:21:00:fb:5c:b6 Kah-Hah
+00:1e:64:27:3b:72 Felix
+40:30:04:4f:de:73 Armin
+00:26:c6:82:51:38 samuirai
+3c:8b:fe:5c:4e:da Moh-Moh
+00:26:bb:69:98:cc Jan
+78:dd:08:d5:34:28 Patrick
+78:ca:39:6e:ed:16 Tillman
+00:22:43:25:61:79 Te vau