Linux信息自動化收集


程序地址: https://github.com/l3m0n/linux_information

兩年前寫的東西,寫的比較爛,公開出來與大家交流一下。

當前權限判斷:是否為root
whoami


1、系統區分
debian系列:debian、ubuntu
redhat系列:redhat、centos

是否為docker、或者為虛擬機

分為通用模塊、單獨模塊的信息獲取


2、系統信息收集

內核(是否為x64還是x86):uname -a

版本:cat /etc/issue
cat /etc/*-release

網絡地址\mac地址\ipv6地址:ifconfig

主機名:hostname

hosts:
cat /etc/hosts
cat /etc/resolv.conf

3、用戶信息

who
last

系統用戶:
獲取用戶名、gid、uid、home路徑:awk -F ':' '{print $1,$3,$4,$6;}' /etc/passwd
獲取用戶組:cat /etc/group
**獲取hash**:cat /etc/shadow

列出超級用戶:grep -v -E "^#" /etc/passwd | awk -F: '$3 == 0 { print $1}'

查看用戶操作:cat ~/.bash_history

獲取在線用戶:w

4、服務程序
需要實現:得到系統安裝程序以及服務,版本信息和運行權限,用文檔封裝一下

端口:netstat
進程:ps -aux
ps -A -o user,pid,tty,start,time,command | grep -E "[^]]$"
程序:
dpkg -l
rpm -qa

5、敏感文件

/etc/目錄下
計划任務
日志文件
bash_history
find / -type f -iname "*.bash_history" -o -iname "*config*" -o -iname "web.xml" -o -iname "*database*" -o -iname "*pass*" 2>/dev/null
config
web.xml

6、常見可使用程序

nmap
nc
netcat
wget
tcpdump
wireshark
rpm
yum
apt-get
ftp
ssh
telnet
scp
nslookup
ruby

6、交互通信的ip

hosts
netstat -antpu
arp -a
tracert

7、提權幫助
根據內核去確認漏洞

8、信息展示
整體流程:信息獲取 -> 信息處理 -> 信息輸出

系統信息:

內核、x86|x64、主機類型、主機名
ip地址、mac地址
是否存在exp獲取root

用戶信息:

存在的用戶、在線用戶
用戶組
last信息
用戶操作信息 .bash_history
用戶hash

服務信息:

端口,可能的服務名
進程,可能的進程名,進程權限,進程開啟時間

文件信息:

敏感文件(password/config/database)
打包文件+運行文件(.zip/.tar.gz/.pl/.sh/.py)
服務配置文件(httpd.conf)
log文件(做處理,只顯示log所在目錄)
常見的信息文件掃描

//需要通過上面獲取的信息整理出來
程序信息:

程序名、程序端口、運行的進程、版本、配置文件

命令信息:

可執行的一些程序

通信信息:

hosts
arp緩存
端口

結構信息:

內網主機存活


9、參考

基礎內核信息:
uname -a 2>/dev/null
cat /proc/version 2>/dev/null
cat /etc/*-release 2>/dev/null

主機名:
hostname 2>/dev/null

最后用戶登錄的信息:
lastlog |grep -v "Never" 2>/dev/null

strips out username uid and gid values from /etc/passwd
cat /etc/passwd | cut -d ":" -f 1,2,3,4 2>/dev/null

列出所有用戶的組
for i in $(cat /etc/passwd 2>/dev/null| cut -d":" -f1 2>/dev/null);do id $i;done 2>/dev/null

查詢是否有hash存儲在/etc/passwd(*nix中)
grep -v '^[^:]*:[x]' /etc/passwd 2>/dev/null


根據uid列出本地用戶:
grep -v "^#" /etc/passwd | awk -F: '$3 == 0 || $3 == 500 || $3 == 501 || $3 == 502 || $3 == 1000 || $3 == 1001 || $3 == 1002 || $3 == 2000 || $3 == 2001 || $3 == 2002 { print }'

讀取shadow文件
cat /etc/shadow 2>/dev/null

bsd的shadow文件
cat /etc/master.passwd 2>/dev/null

能夠sudo不需要提供密碼
echo '' | sudo -S -l 2>/dev/null

檢查root目錄是否存在
ls -ahl /root/ 2>/dev/null

顯示home目錄情況
ls -ahl /home/ 2>/dev/null

尋找文件我們能寫但是不屬於我們的文件
find / -writable -not -user \`whoami\` -type f -not -path "/proc/*" -exec ls -al {} \; 2>/dev/null

尋找ssh公鑰
find / -name "id_dsa*" -o -name "id_rsa*" -o -name "known_hosts" -o -name "authorized_hosts" -o -name "authorized_keys" 2>/dev/null |xargs -r ls

root是否能登錄ssh
grep "PermitRootLogin " /etc/ssh/sshd_config 2>/dev/null | grep -v "#" | awk '{print  $2}'
如果返回yes則可以登錄

環境變量
echo $PATH 2>/dev/null

列出能用的shells
cat /etc/shells 2>/dev/null

hash的密碼加密政策
cat /etc/login.defs 2>/dev/null | grep "PASS_MAX_DAYS\|PASS_MIN_DAYS\|PASS_WARN_AGE\|ENCRYPT_METHOD" 2>/dev/null | grep -v "#" 2>/dev/null

所有的計划任務配置文件
ls -la /etc/cron* 2>/dev/null

獲取計划任務內容
cat /etc/crontab 2>/dev/null

ubuntu獲取計划任務
ls -la /var/spool/cron/crontabs 2>/dev/null

ls -la /etc/anacrontab 2>/dev/null; cat /etc/anacrontab 2>/dev/null
ls -la /var/spool/anacron 2>/dev/null

獲取每個用戶的計划任務
cat /etc/passwd | cut -d ":" -f 1 | xargs -n1 crontab -l -u 2>/dev/null

獲取ifconfig

/sbin/ifconfig -a 2>/dev/null

dns設置
cat /etc/resolv.conf 2>/dev/null | grep "nameserver"

路由配置
route 2>/dev/null | grep default

正在監聽的tcp端口
netstat -antp 2>/dev/null

udp端口
netstat -anup 2>/dev/null

正在運行的程序
ps aux 2>/dev/null

查看進程路徑和權限
ps aux | awk '{print $11}'|xargs -r ls -la 2>/dev/null |awk '!x[$0]++'

獲取inetd.conf文件(監視網絡的守護進程)
cat /etc/inetd.conf 2>/dev/null
cat /etc/inetd.conf 2>/dev/null | awk '{print $7}' |xargs -r ls -la 2>/dev/null
cat /etc/xinetd.conf 2>/dev/null
cat /etc/xinetd.conf 2>/dev/null | awk '{print $7}' |xargs -r ls -la 2>/dev/null

列舉各種服務的管理腳本
ls -la /etc/init.d 2>/dev/null
尋找不是root的:
find /etc/init.d/ \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null

ls -la /etc/rc.d/init.d 2>/dev/null
find /etc/rc.d/init.d \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null
ls -la /usr/local/etc/rc.d 2>/dev/null

find /usr/local/etc/rc.d \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null

獲取mysql版本
mysql --version 2>/dev/null
mysqladmin -uroot version 2>/dev/null

獲取sudo版本
sudo -V 2>/dev/null| grep "Sudo version" 2>/dev/null

測試root/root能否登錄
mysqladmin -uroot -proot version 2>/dev/null

postgres版本
psql -V 2>/dev/null
登錄成功
psql -U postgres template0 -c 'select version()' 2>/dev/null | grep version

apache詳情
apache2 -v 2>/dev/null; httpd -v 2>/dev/null

apache的運行用戶
cat /etc/apache2/envvars 2>/dev/null |grep -i 'user\|group' |awk '{sub(/.*\export /,"")}1'

plan(could contain useful information)
find /home /usr/home -iname *.plan -exec ls -la {} \; -exec cat {} 2>/dev/null \;
rhosts(these may allow us to login as another user etc.)
find /home -iname *.rhosts -exec ls -la {} 2>/dev/null \; -exec cat {} 2>/dev/null \;

.plan
.rhosts
hosts.equiv
/etc/exports
.conf
.log
.ini
.*_history
/root/.*_history
ls -la /var/mail 2>/dev/null
head /var/mail/root 2>/dev/null

軟件安裝判斷流程

dpkg -l
rpm -qa

etc目錄配置文件


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM