kali环境维护的一些命令

git拉取冲突

#删除本地修改,直接拉取最新
git reset --hard
git pull

docker容量满,清理镜像

docker system prune -a

docker停止删除所有容器和删除镜像

停止所有容器
删除所有容器
删除所有镜像
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker image rm $(docker image ls -q)

docker拉取超时,登录docker

#至官网注册登录docker账号并创建access(需先配置下方代理)
Personal access tokens-New access token


└─# docker login -u ddosploit
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
sudo mkdir -p /etc/systemd/system/docker.service.d/ && \
sudo bash -c 'echo -e "[Service]\nEnvironment=\"HTTP_PROXY=http://192.168.136.1:8888/\"\nEnvironment=\"HTTPS_PROXY=http://192.168.136.1:8888/\"\nEnvironment=\"NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com\"" > /etc/systemd/system/docker.service.d/http-proxy.conf' && \
sudo systemctl daemon-reload && \
sudo systemctl restart docker
sudo systemctl show --property=Environment docker
sudo rm /etc/systemd/system/docker.service.d/http-proxy.conf
sudo systemctl daemon-reload
sudo systemctl restart docker

python多版本并存切换版本

(因kali经常更新,一些python包装在之前版本,python版本变动导致一些软件无法运行)

#检查kali目前已安装几个版本python,发现有v2、v3(9-11)
┌──(kali㉿kali)-[~/Desktop/Mobile-Security-Framework-MobSF]
└─$ python
Completing external command
python              python2.7-config    python3.9           python3.11-config   python3-futurize    python3-wsdump                                          
python2             python2-config      python3.10          python3-commonmark  python3-pasteurize  python-dotenv                                           
python2.7           python3             python3.11          python3-config      python3-qr          python-faraday 




或直接使用命令清除所有
update-alternatives --remove-all python
update-alternatives --remove-all python2
update-alternatives --remove-all python3

#验证是否移除python python2 python3配置
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --config python                    
update-alternatives: error: no alternatives for python
                                                                                                                                                
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --config python2
update-alternatives: error: no alternatives for python2
                                                                                                                                                
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --config python3
update-alternatives: error: no alternatives for python3


#配置python、python3可切换
添加python命令的3.9 
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1 
update-alternatives: using /usr/bin/python3.9 to provide /usr/bin/python (python) in auto mode
添加python命令的3.10 
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --install /usr/bin/python python /usr/bin/python3.10 2
添加python命令的3.11
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --install /usr/bin/python python /usr/bin/python3.11 3 
update-alternatives: using /usr/bin/python3.11 to provide /usr/bin/python (python) in auto mode



添加python3命令的3.9                                                                                                                                            
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
update-alternatives: using /usr/bin/python3.9 to provide /usr/bin/python3 (python3) in auto mode

添加python3命令的3.10 

┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 3
update-alternatives: using /usr/bin/python3.10 to provide /usr/bin/python3 (python3) in auto mode

添加python3命令的3.11                                                                                                                                               
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 4
update-alternatives: using /usr/bin/python3.11 to provide /usr/bin/python3 (python3) in auto mode



#验证python命令和python3命令的版本配置,并配置为默认3.10

┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --config python 
There are 3 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                 Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.11   2         auto mode
* 1            /usr/bin/python3.10   1         manual mode
  2            /usr/bin/python3.11   2         manual mode
  3            /usr/bin/python3.9    1         manual mode

 
                                                                                                                                             
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# update-alternatives --config python3
There are 3 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                 Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.11   4         auto mode
* 1            /usr/bin/python3.10   3         manual mode
  2            /usr/bin/python3.11   4         manual mode
  3            /usr/bin/python3.9    2         manual mode



#验证python命令和python3命令,此时所有命令均正常预期
                                                                                                                                                
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# python 
Python 3.10.8 (main, Jan 16 2022, 17:12:18) 

                                                                                                                                                
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# python3
Python 3.10.8 (main, Jan 16 2022, 17:12:18) 

                                                                                                                                                
┌──(root㉿kali)-[/home/kali/Desktop/caringcaribou/tool]
└─# python2
Python 2.7.18 (default, Aug  1 2022, 06:23:55) 

debian更换kali源及GPD error错误

kali@kali:~$ grep -v '#' /etc/apt/sources.list | sort -u
deb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware

kali@kali:~$

kali@kali:~$ echo deb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware >/etc/apt/sources.list
kali@kali:~$ wget -q -O - https://archive.kali.org/archive-key.asc | apt-key add 

apt update提示”W: http://http.kali.org/kali/dists/kali-rolling/InRelease: Key is stored in legacy trusted”

rm -rf /var/lib/apt/lists
apt-get update
apt-get install kali-archive-keyring

使用update-alternatives切换python版本之后apt报错

apt update报错信息:ModuleNotFoundError: No module named ‘apt_pkg’

┌──(root㉿kali)-[/usr/lib/python3/dist-packages]
└─# cp apt_pkg.cpython-311-x86_64-linux-gnu.so apt_pkg.cpython-310-x86_64-linux-gnu.so

python3切换版本后pip版本未切换

curl https://bootstrap.pypa.io/get-pip.py | python3

设置时区

sudo timedatectl set-timezone Asia/Shanghai
[root@ccych72457obbe ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        3.9G     0  3.9G   0% /dev
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           3.9G  330M  3.5G   9% /run
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda1        40G   36G  1.8G  96% /
tmpfs           781M     0  781M   0% /run/user/0

查看根目录占用大小
du -h --max-depth=1 /


┌──(root㉿kali)-[/home/kali]
└─# cd ./.cache/

┌──(root㉿kali)-[/home/kali/.cache]
└─# du -h --max-depth=1
8.0K	./hashcat
8.0K	./pocl
3.9M	./fontconfig
8.0K	./dconf
4.0K	./obexd
17G	./vmware
148K	./RiseupVPN
16K	./sessions
4.0K	./doc
52K	./dirb
240M	./mozilla
448K	./samba
32K	./xfce4
4.0K	./gvfsd
4.0K	./mesa_shader_cache
4.0K	./gvfs
912M	./go-build
1.1M	./gstreamer-1.0
1.8M	./thumbnails
18G	.


rm -rf ./vmware

查找大文件
find / -type f -size +500M

删除目录下所有某日志文件
rm -f svr.*

清除内容
> access.log
┌──(root㉿kali)-[/home/kali/Desktop]
└─# apt update 
Get:1 http://kali.download/kali kali-rolling InRelease [41.5 kB]
Err:1 http://kali.download/kali kali-rolling InRelease
  The following signatures were invalid: EXPKEYSIG ED444FF07D8D0BF6 Kali Linux Repository <[email protected]>
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
1153 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://kali.download/kali kali-rolling InRelease: The following signatures were invalid: EXPKEYSIG ED444FF07D8D0BF6 Kali Linux Repository <[email protected]>
W: Failed to fetch http://http.kali.org/kali/dists/kali-rolling/InRelease  The following signatures were invalid: EXPKEYSIG ED444FF07D8D0BF6 Kali Linux Repository <[email protected]>
W: Some index files failed to download. They have been ignored, or old ones used instead.

┌──(root㉿kali)-[/home/kali/Desktop]
└─# wget -q -O - https://archive.kali.org/archive-key.asc | apt-key add
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
powershell
$env:MAVEN_OPTS="-DsocksProxyHost=192.168.136.1 -DsocksProxyPort=9999"
mvn clean integration-test -P fortify-sca

cmd
set MAVEN_OPTS=-DsocksProxyHost=192.168.136.1 -DsocksProxyPort=9999
mvn clean integration-test -P fortify-sca
cmd
# 设置环境变量
set http_proxy=socks5://192.168.136.1:9999
set https_proxy=socks5://192.168.136.1:9999

powershell
# 设置环境变量
$env:HTTP_PROXY = "http://192.168.136.1:9999"
$env:HTTPS_PROXY = "http://192.168.136.1:9999"


git clone https://github.com/WebGoat/WebGoat

kali linux 2026不支持Cobalt Strike4.9.1

kali2026默认为jdk25版本,版本太高需降级到21左右,因4.9.1为2022年左右发布
apt-cache search '^openjdk-[0-9]+-jdk$'
apt install openjdk-21-jdk

1.查看网络连接

┌──(kali㉿pentest)-[~/Desktop/导航页]
└─$ netstat -antpl
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:39499         0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:8090            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:5002            0.0.0.0:*               LISTEN      2689510/python      
tcp        0      0 0.0.0.0:5001            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:5173            0.0.0.0:*               LISTEN      -                   
tcp        0    368 192.168.110.106:22      192.168.110.202:42036   ESTABLISHED -                   
tcp6       0      0 :::22                   :::*                    LISTEN      -                   
tcp6       0      0 :::8000                 :::*                    LISTEN      -                   
tcp6       0      0 :::5432                 :::*                    LISTEN      -                   
tcp6       0      0 :::5173                 :::*                    LISTEN      -        

2.找到5001端口所在进程

└─$ sudo fuser 5001/tcp
[sudo] password for kali: 
5001/tcp:            627891

3.查看进程完整路径

└─$ sudo ls -l /proc/627891/cwd
lrwxrwxrwx 1 root root 0 Sep 18 11:39 /proc/627891/cwd -> /home/kali/Desktop/漏洞通告

4.结束进程

└─$ sudo kill 627891            
[sudo] password for kali: