KALI study notes (to be continued)

DAY1 system installation

  1. Burn KALI image with U disk, without live start, including amd64, 4G
  2. Start the installation graphical interface with u disk, select simple Chinese-Chinese, default KFCE, full tools
  3. Change password, sudo passwd root, original password, new password, new password, log out and log in with root, change win10 style
  4. Install Wubi, apt update, apt-get install fcitx fcitx-table-wubi, reboot
  5. 1 Download cs1.6 at linuxgame.cn
  6. 2 dpkg all wine32 --add-architecture i386 && apt-get update && apt-get inst
  7. 3 dpkg-reconfigure locales install en_US.UTF-8 and select it as the default, double-click to open
  8. 1 Download pal98 at linuxgame.cn
  9. 2 chmod +x ./sdlpal-linux
  10. 3. Open ./sdlpal-linux
  11. 1 Download vscode, apt install ./code_1.54.3-1615806378_amd64.deb
  12. 2 Open vscode, install Chinese plug-in, test md file and python file operation, pay attention to use python3 command
  13. 3 File-Preferences-Settings-Terminal>Integrated: Font is set to Hack,'Courier New', monospace
  14. Finish DAY1 with a pictureInsert picture description here

DAY2 basic operation

ls -alh --sort=time,含.隐蒧文件,列表,最佳单位,按时间排序,time改size按大小排序
cd ..,切换至父路径
pwd,显示当前路径
cat /etc/passwd,显示文件内容
more /etc/passwd,换页显示文件内容
less /etc/passwd,同上但不会显示百分比,q退出
head -1 /etc/passwd,显示文件头一行
tail -1 /etc/passwd,显示文件末一行
watch -n 2 tail -20 /var/log/messages,每两秒刷新,ctrl+c退出
dmesg,同cat /var/log/messages
touch 1.txt,创建空文件
cp 1.txt 2.txt,复制文件
rm 2.txt,删除文件
mkdir 123,创建路径
rm -r 123,删除路径
top,当前系统资源使用情况
ps -ef,进程信息,e所有,f详细
ps aux,功能同上,有列顺序区别
grep ssh /etc/passwd,选文件中含关键词的行
ifconfig,网络配置信息
ifconfig eth0 down,卸网卡
macchanger -m 00:11:11:11:11:11,改ip(仅本次登陆有效)
ifconfig eth0 up,装网卡
netstat -pantu,查看tcp与udp连接
netstat -pantu | egrep -v '0.0.0.0|:::',同上但去掉含在有0.0.0.0与:::的行
netstat -pantu | egrep -v '0.0.0.0|:::' | awk '{print $5}',只显示第五列的内容
netstat -pantu | egrep -v '0.0.0.0|:::' | awk '{print $5}' | egrep -v 'and|Address',再去掉含有and与
Address的行
netstat -pantu | egrep -v '0.0.0.0|:::' | awk '{print $5}' | egrep -v 'and|Address' | cut -d ':' -f 1,
以:分隔取第一块即IP
netstat -pantu | egrep -v '0.0.0.0|:::' | awk '{print $5}' | egrep -v 'and|Address' | cut -d ':' -f 1 
| sort | uniq,排序并去掉重复
netstat -pantu | egrep -v '0.0.0.0|:::' | awk '{print $5}' | egrep -v 'and|Address' | cut -d ':' -f 1 
| sort | uniq > 1.txt,覆盖写入文件
netstat -pantu | egrep -v '0.0.0.0|:::' | awk '{print $5}' | egrep -v 'and|Address' | cut -d ':' -f 1 
| sort | uniq >> 1.txt,追加写入文件
mount,查看挂载信息
mount -o loop kali.iso /media/cdrom,挂载iso
find / -name nmap,找出系统中所有叫namp的文件
find / -iname nmap,找出系统中所有叫namp的文件,且不区分大小写
find . -name "1*",找出当前路径中以1开头的文件
find . -name "1*" -exec cp {} ./{}.bak \;  ,复制到当前目录下并重命名为末尾.bak,\;表示-exec语句结束 
echo 123,输出123,详见shell教程
cd aaa & ls,管道符&表示依次执行,有错也继续
cd aaa && ls,管道符&&表示依次执行,有错终止
updatedb,更新数据库让whereis查找
whereis nmap,找出通过deb包安装的程序
whereis -b nmap,找出名称叫nmap的二进制可执行文件
deb包:用dpkg -i安装,用于ubuntu与debian(kali),apt可以自动安装deb包需要的依赖,apt即Advanced Package Tool
rpm包:用rpm安装,用于red-hat与centos,yum可以自动安装rpm包需要的依赖,rpm即Red-hat Package Manager
源码包:./configure,make,make install,三步曲安装,用于全linux系统
-----------------------------------------------------------------------
tree			查看当前目录树
sync			数据同步到硬盘
halt			立即关机
shutdown -h now		同上
shutdown -h 20:25	指定时间关机
shutdown -h +10		十分钟后关机
reboot			立即重启
shutdown -r now		同上
shutdown -h 20:25	指定时间重启
shutdown -r +10		十分钟后重启

DAY3 network configuration

//自动获取DHCP地址:eth0是网卡名称
dhclient eth0
//查看现在的路由表
netstat -nr
//手动设置地址并添加路由:default是默认路由0.0.0.0,gw是网关
ifconfig eth0 192.168.1.11/24
route add default gw 192.168.1.1
//查看现在的路由表
route -n
//添加网段
route add -net 192.168.1.0/24
//写入配置文件
echo nameserver 192.168.1.1 > /etc/resolv.conf
//修改ip配置文件
vim  /etc/network/interfaces
//esc,:wq,enter,重启生效

DAY4 update package

vim /etc/apt/sources.list
deb http://mirrors.ustc.edu.cn/kali kali main non-free contrib
deb-src http://mirrors.ustc.edu.cn/kali kali main non-free contrib
deb http://mirrors.ustc.edu.cn/kali-security kali/updates main non-free
apt-get update
apt-get upgrade
apt-get dis-upgrade改
如果重启后提示变英语,记住不要变
不幸变了的修改方法,tzselect选上海,dpkg-reconfigure locales,像选CS那样重新选再重启

DAY5 system software

Media Player:apt-get install smplayer
软件包安装程序:apt-get install gdebi
差异查看器: apt-get install meld
CHM viewer:apt-get install kchmviewer
FTP client:filezilla filezilla-common
My traceroute:apt-get install mtr
微软字体:apt-get install ttf-wqy-microhei
!!!!这个实在太重要了,可以打开OD没乱码,运行wine notepad.exe也没乱码,可以正确执行exe程序

DAY6 Firefox plugin

cookie importer
cookiemanager:管理cookie
flagfox:显示站点国家
hackbar:页面F9操作跨站及sql注入
live http headers:查看http包包头
user agent switcher:更改浏览器类型

DAY7 install JAVA

下载地址:https://www.oracle.com/java/technologies/javase-downloads.html
下载JDK:jdk-8u281-linux-x64.tar.gz
cd /root/下载
tar -xzvf jdk-8u281-linux-x64.tar.gz
mv jdk1.8.0_281 /root/programme/JDK8
cd /root/programme/JDK8
vim ~/.zshrc
  # install JAVA JDK
  export JAVA_HOME=/root/programme/JDK8/jdk1.8.0_281
  export CLASSPATH=.:${JAVA_HOME}/lib
  export PATH=${JAVA_HOME}/bin:$PATH
source ~/.zshrc
update-alternatives --install /usr/bin/java java /root/programme/JDK8/jdk1.8.0_281/bin/java 1
update-alternatives --install /usr/bin/javac javac /root/programme/JDK8/jdk1.8.0_281/bin/javac 1
update-alternatives --set java /root/programme/JDK8/jdk1.8.0_281/bin/java
update-alternatives --set javac /root/programme/JDK8/jdk1.8.0_281/bin/javac
update-alternatives --set java /root/programme/JDK8/jdk1.8.0_281/bin/java
update-alternatives --set javac /root/programme/JDK8/jdk1.8.0_281/bin/javac
java -version
javac -version
-----------------------------------------------------
使用javac与java时如果有警告,执行unset _JAVA_OPTIONS即可
或者vim /etc/profile把上面那行指令加到最后再source /etc/profile  

DAY8 install office software----

安装libreoffice:
apt-get install libreoffice-l10n-zh-cn

安装mysql:
sudo apt-get install mysql-server
sudo mysql_secure_installation
输入密码abccba两次回车确认
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
Remove anonymous users? (Press y|Y for Yes, any other key for No) : n
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
sudo mysql -uroot -p
abccba [enter]
exit 退出

安装花生壳:
在官网https://hsk.oray.com/download/下载deb文件
在下载目录打开命令行执行sudo dpkg -i phddns-5.0.0-amd64.deb 
看官网https://service.oray.com/question/11630.html教程
网页端初次登陆用安装时的SN码登陆管理端,之后微信扫码登陆
本地phddns start运行,运行django等即可

安装sqlite3:
sudo apt-get install sqlite3
驱动->数据库->数据表->属性->数据
sqlite3
.open test.db
.table
.schema users
select * from users;
.exit

DAY9 concurrent thread limit

ulimit -a,可以看到所有限制,以及参数
ulimit -s 100,可以限制每个线程的堆栈大小是100KB,控制台执行仅临时生效
vim ~/.zshrc,把上一行加到最后,保存退出,永久生效

DAY10 service switch

/etc/init.d/ssh start
netstat -pantu | grep :22
/etc/init.d/ssh stop
netstat -pantu | grep :22
注意:kali默认未启动所有网络服务
update-rc.d A defaults 80 20
update-rc.d B defaults 90 10
上面两行功能:开机时A服务优先于B启动,关机时B服务优先于A关闭

DAY11 shell

理解:linux指令其实就是shell编程语句
有点类似python可以有交互式控制台那样



1局部变量
vim cjshell.sh
	#!/bin/bash
	echo "hello,world!"
	echo "PATH=$PATH"
	echo "USER=$USER"
	echo "SHELL=$SHELL"
	echo "PWD=$PWD"
	echo "HOME=$HOME"
	a=3
	echo "$a"
	unset a
	echo "$a"
	readonly b=3
	#unset b
	c=$a+$b
	echo "$c"
	RESULT=`ls -l /home`
	echo "$RESULT"
	echo ""
	echo "$(date)"
	:<<!
		this is the comment
	!
sh ./cjshell.sh
输出成功
不用sh的输出写法如下:
chmod 777 cjshell.sh
./cjshell.sh或/root/cjfile/cjshell.sh



2全局变量:
vim /etc/profile
	在文末添加
	cj_variable=3
	export cj_variable
source /etc/profile
echo $cj_variable
vim gjlshell.sh 
	#!/bin/bash
	echo "$cj_variable"
sh ./gjlshell.sh 
输出成功
【如果无export cj_variable】
【上面的echo也可以成功输出】
【但若是.sh文件执行就不能】



3位置变量:
vim love.sh
	#!/bin/bash
	echo $0
	echo $1
	echo $2
	echo $*
	echo $@
	echo $#
sh love.sh 100 200
关于$*与$@的不同见下例:
vim tt.sh
	#! /bin/bash
	test() {
        	echo "未加引号,二者相同"
        	echo $*
       		echo $@
        	echo "加入引号后对比"
		echo "----"\$*----""
        	for N in "$*"
        	do
        	   echo $N
        	done
		echo "----"\$@----""
        	for N in "$@"
        	do
        	   echo $N
        	done
	}
	test  11 22 33
sh tt.sh
	未加引号,二者相同
	11 22 33
	11 22 33
	加入引号后对比
	----$*----
	11 22 33
	----$@----
	11
	22
	33



4预定义变量
echo $$	当前进程PID
echo $!	后台最后一个进程的PID
echo $?	最后一次执行命令的返回态(0正常)
示例:
vim love.sh
	#!/bin/bash
	echo $$
	sh ./gjlshell.sh &
	echo $!
	echo $?
vim gjlshell.sh
	#! /bin/bash
	echo "go"
sh ./love.sh
输出成功



5运算
#! /bin/bash
a=1
b=2
echo $((4*($a+$b)))
echo $[4*($a+$b)]
tmp=`expr $a + $b`
echo `expr $tmp \* 4`
【总结:用第二种即可,即$[]】
【注意:echo 4*(3+2)会输出字符串】
【原因:$[]可以对[]里面的式求值】
echo 4*(3+2)
echo $[4*(3+2)]
上面的数字随机可以改为 $变量名



6流程
=等
-lt小
-lt小等
-eq等
-gt大
-ge大等
-ne不等
-r可读
-w可写
-x可执行
-f存在文件
-d存在目录
-e存在文件或目录
【其实目录也是文件,我这么说是为了好理解】

vim gjlshell.sh

#! /bin/bash
if [ $1 = "cj" ]
then
        echo "111"
fi
if [ $2 -gt 60 ]
then
        echo "222"
elif [ $2 -lt 60 ]
then
        echo "333"
fi
if [ -f "head_sculpture.jpg" ]
then
        echo "444"
fi
for i in "$*"
do
        echo $i
done
for i in "$@"
do
        echo $i
done
sum=0
for (( i=1;i<=100;i++  ))
do
        sum=$[$sum+$i]
done
echo $sum
i=0
sum2=0
while [ $i -le $2 ]
do
        sum2=$[$sum2+$i]
        i=$[$i+1]
done
echo $sum2

sh ./gjlshell.sh cj 61



7交互
read(选项)(参数)
-p指定读取值提示符
-t指定读取等待时间
vim love.sh

read x
echo $[$x+1]
read -p "input please:" y
echo  $[$y+1]
read -t 3 z
echo $z+"zz"+3 

sh ./love.sh 



8函数
basename /home/aaa/test.txt
返回test.txt
basename /home/aaa/test.txt .txt
返回test
dirname /home/aaa/test.txt
返回home/aaa

function funname(){
	Action;
	return int;
}
示例:
vim cjshell.sh

#! /bin/bash
function cj_max(){
        echo "cj";
}
cj_max

function cj_add(){
        echo $[$x+$y];
        return $[$x+$y+10];
}
read x
read y
cj_add $x $y
echo $?

sh ./cjshell.sh



9计划
vim /root/cjfile/plan.sh
#!/bin/bash
date >> /root/cjfile/test3.txt
echo "cj" >> /root/cjfile/test3.txt

crontab -e
* * * * * ls -al /root/cjfile/ >> /root/cjfile/test1.txt
* * * * * date >> /root/cjfile/test2.txt
* * * * * . /root/cjfile/plan.sh

-e是编加的意思
第一个*表示时中第几分,0-59
第二个*表示天中第几时,0-23
第三个*表示月中第几天,1-31
第四个*表示年中第几月,1-12
第五个*表示周中星期几,0-7(0与7都是周日)
【如果是*表示全选所有值都执行】

例一:每天三点与八点执行一次 /bin/ls:
* 3,8 * * * /bin/ls
例二:在 12 月内, 每天的早上 6 点到 12 点,每隔 3 个小时 0 分钟执行一次 /usr/bin/backup:
0 6-12/3 * 12 * /usr/bin/backup
例三:周一到周五每天下午 5:00 寄一封信给 [email protected]:
0 17 * * 1-5 mail -s "hi" [email protected] < /tmp/maildata
例四:每月每天的午夜 0 点 20 分, 2 点 20 分, 4 点 20 分....执行 echo "haha":
20 0-23/2 * * * echo "haha"

对了,>>叫做追加,>叫做覆盖写



10压缩
gzip只能压缩文件且会删原文件,多个文件传入是分别压缩
gzip p1.jpg p2.jpg 
gunzip p1.jpg.gz p2.jpg.gz

zip能压缩目录且会保留原文件
zip -r aaa.zip aaa
unzip aaa.zip
-d选择压缩或解压宿文件生成的目录
-r递归压缩或解压缩,对目录操作时用,示例中aaa是非空目录
【如果示例中没有-r,将来解压会得到空目录aaa】

tar能压缩目录且会保留文件
tar -zcvf aaa.tar.gz aaa
【-c是接收传入文件/目录打包成tar,-z是把打包好的tar压缩到gz,-v是显示过程信息,-f是指定gz压缩包的名字】
tar -zxvf aaa.tar.gz 
【-z是接收传入的gz文件解压成tar,-x是把解压好的tar解包成原文件,-v是显示过程信息,-f是指定压缩包的名字】
mkdir xyz
tar -zxvf abc.tar.gz -C ./xyz/
【-C是指定解压路径,如省略则默认是本目录下】


DAY12 vim

vim编辑器
一进入就是默认模式
·在默认模式下,数字+空格就是光标往后移动的字符数,/加关键词可以搜索,dd删行,u撤销
按i进入编辑模式,按esc返回默认模式
·在编辑模式下,就是正常的增删改查即可
按:进入命令模式,按esc返回默认模式,或按enter执行命令退出或返回默认模式
·在命令模式下,:wq是保存退出,:q!是不保存退出,:set nu显示行号

DAY13 user

用户管理在kali中是用不到的~仅作了解
useradd -m gjl	创建gjl用户,并在home下创建主目录,省略-m亦可,加-G可以定义用户组(这个一开始就要分配好)
userdel -r gjl	删除gjl用户,并把home下主目录删除,省略-r需手动删
cat /etc/passwd	查看用户信息,可以看到用户ID,以及用户的主目录(想更改可以用usermod -d user new_path)
……用户久,口令,用户标识号,组标识号,注释性描述,主目录,登陆shell
su - 用户名	切换用户,不加-的话切换后还是在现在的目录下,加了就跳到该用户主目录
hostname	查看主机名
hostname cj	改主机名为cj
passwd cj	给cj用户改密码,连输两次即可(普通用户只能改自己密码,直接passwd即可)
passwd -l cj	锁住cj用户
passwd -u cj	解锁cj用户
groupadd g1	创建用户组g1,id自增1
groupadd -g 520 g2		创建用户组g2,并设id为520
groupmod -g 666 -n g3 g2	把用户组g2的id改为666,并改名为g3(不建议改名)
cat /etc/group	查看用户组信息,可以看到组ID(1000开始是用户自设的,默认一个账户一个组)
groupdel g1	删除用户组g1,注意如果当前组下有用户的话是删不了的
举例:groupmod -n gjl cj
执行前查cat /etc/group得到cj:x:520:
执行后查cat /etc/group得到gjl:x:520:cj

DAY14 disk

df	列出文件系统整体磁盘使用量:文件系统名/大小/已用/可用/已用百分比/挂载点
df -h	同上,换成KMG做单位(上面是字节做单位),感觉主要就是看/dev/vda1这个40G,其他挂载的也不知是啥
du	列出当前目录下各文件或目录的大小,以B做单位
du -h	列出当前目录下各文件或目录的大小,以KMG做单位
du -sm /*	-s表示只看后面路径下所有一级目录的大小,-m表示一定以M做单位
mount /dev/myUpan /mnt/myUpan	把/dev下的myUpan挂载到/mnt下的myUpan
unmount -f /mnt/myUpan		强制卸载

DAY15 process

ps	查看当前系统中正在执行的各种进程的信息
ps -a	当前终端运行的所有进程信息
ps -u	以用户信息显示进程
ps -x	显示后台运行进程参数
ps -x	显示父进程id
ps -au | grep root	查看进程运行情况并过滤出含出root的行
pstree		显示进程树
pstree -p	显示进程树及父ID
pstree -u	显示进程树及用户组
kill -9 id	强制杀死进程

DAY16 link

touch f1	创建f1,应该说f1存了真正的文件地址,可以理解为f1自身就是一个硬链接
ln f1 f2	给f1创建硬链接f2
硬链接:f1与f2指向同一文件(即一个文件有多个路径),有保险作用,只有所有硬链接都删了这个文件才真正删掉
ln -s f1 f3	给f1创建软链接f3
ln -s f2 f4	给f2创建软链接f4
软链接:不直接存文件地址而是存f1的址,不管f1指向的文件是否存在,实际访问时先找到f1再找文件
ls -al		可以看到f1与f2是-即文件,f3是l即软链接
echo 'cj' >> f1	往f1写入文件,(这里与往f3与f2写入完全一样)
rm f1		此时文件并未真正删除
cat f2		可访问
cat f3		不可访问
cat f4		可访问
rm f2		此时文件才是真正删除
cat f3		不可访问
cat f4		不可访问

DAY17 experimental environment

Buy Alibaba Cloud server and write down the public network ip
apt-get install ssh
ssh public network ip

DAY18 netcat

Parameters:
-g<gateway> Set the hop-range communication gateway of the router, up to 8 can be set.
-G<number of pointers> Set the source routing pointer, and its value is a multiple of 4.
-h Online help.
-i <delay in seconds> Set the time interval to transmit information and scan communication ports.
-l monitor mode, used for inbound connection (monitoring local port).
-n Use the IP address directly, not through the domain name server.
-o<output file> Specify the file name, dump the data transmitted back and forth in hexadecimal characters into the file and save it.
-p<communication port> Set the communication port used by the local host.
-q 1 Disconnect after 1 second after the transfer (file).
-r Randomly specify the communication port between the local and remote hosts.
-s<source address> Set the IP address of the data packet sent by the local host.
-u Use UDP transport protocol.
-v displays the instruction execution process.
-w<timeout seconds> Set the time to wait for connection.
-z Use 0 input/output mode, only used when scanning communication ports.
Usage example 1: The server and the client communicate with each other
Server: nc -l -p 333
Client: nc -nv 39.101.184.108 333
Usage example 2: The client transmits files to the server (package the directory first)
Server: nc -l -p 333> 1.txt
client: nc -nv 39.101.184.108 333 <1.txt -q 1
Usage example 3: The server transmits files to the client (package the directory first)
Server: nc -q 1 -l -p 333 <1.txt
Client: nc -nv 39.101.184.108 333> 2.txt
Usage example 4: Scan server port
Client: nc -nvz 39.101.184.108 1-65535
use Example 5: Clone hard disk
Server: nc -lp 333 | dd of=/dev/sda
Client: dd if=/dev/sda | nc -nv 39.101.184.108 333 -q 1

DAY19 wireshark

1 Analysis of packet capture and sniffing protocol

  • Promiscuous mode: After checking, you can capture broadcast packets that are not sent to you.
    2 Required skills for security experts.
    3. Packet capture engine:
  • Libpcap-Linux
  • Winpcap-Win10
    4 decoding capability

Example of use:

  1. Open two terminals locally, and log in to the cloud server with one SSH
  2. Open the software, capture eth0 network card, filter host 39.101.184.108
  3. The cloud terminal executes nc -lp 333 and observes that two ssh and one tcp packets are captured
  4. This terminal executes nc -vn 39.101.184.108 333 to capture three tcp packets
  5. This terminal executes 1, and captures two tcp, one ssh, and one tcp
  6. stop,file-save,choose the path to save

Recommendations:

  1. The recommended saving format is pcap, because all packet capture software is compatible
  2. Edit-Preferences, add the required attributes in the column tab
  3. No. Time SRC_MAC DST_MAC SRC_IP DST_IP SRC_PORT DST_PORT Protocol Length Info
  4. Dynamically add filters can be entered at the bottom of the widget toolbar
  5. Right-click the captured data-apply as a filter-select/unselect to generate a filter
  6. Right-click the captured data -decode as-http, can interpret non-80 port http packets
  7. Right-click the captured data-trace flow-tcp flow, which can interpret non-80 port http packets

Guess you like

Origin blog.csdn.net/cj1064789374/article/details/114916795