-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSenInfo.py
163 lines (156 loc) · 5.13 KB
/
SenInfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import os
import time
#py2
filename = time.strftime('%Y%m%d_%H%M%S', time.localtime())+'seninfo.txt'
fileObj = open(filename)
def baseInfo():
#all system info
fileObj.writelines('\n+++++++Basic Info+++++++++++ \n')
cmd = 'uname -a'
fileObj.writelines(' ******'+cmd + '********* : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#kernel version
cmd = 'cat /proc/version'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#relese info
cmd = 'cat /etc/*-release'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#cpu info
cmd = 'cat /proc/cpuinfo'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#document info
cmd = 'df -a'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
def UserInfo():
#all user
fileObj.writelines('\n +++User Info \n')
cmd = 'cat /etc/passwd'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#all group
cmd = 'cat /etc/group'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#all user hash
cmd = 'cat /etc/shadow'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#now login
cmd = 'who -a'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#now logined user and the process
cmd = 'w'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#the uses logined
cmd = 'last'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#the users last login
cmd = 'lastlog'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
def SysInfo():
#history command
fileObj.writelines('\n +++System Info \n')
cmd = 'history'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#useful shell
cmd = 'cat /etc/shells'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
def FileInfo():
fileObj.writelines('\n +++File Info \n')
#find SUID file
cmd = 'find / -perm -4000 -type f'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#find root SUID file
cmd = 'find / -uid 0 -perm -4000 -type f'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#find pass log
cmd = ' grep -l -i pass /var/log/*.log'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#apache info
cmd = 'apache2 -v'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#mysql info
cmd = 'mysql --version'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#perl version
cmd = 'perl -v'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#iptables info
cmd = 'iptables -L'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#port info
cmd = 'netstat -an'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
#service info
cmd = 'cat /etc/services'
fileObj.writelines(' ********'+cmd + '*********** : \n')
textlist = os.popen(cmd).readlines()
for line in textlist:
fileObj.writelines(line)
if __name__ == '__main__':
baseInfo()
UserInfo()
SysInfo()
FileInfo()