0x02[web]servlet相关知识

servlet相关知识

1.HttpSessionListener 和 HttpSessionBindingListener

HttpSessionListener:
setAttribute(‘xxx’,HttpSessionBindingListener的实现) 的时候,会触发事件。 绑定在attribute上

HttpSessionBindingListener:
web容器上。容器上的session注册和失效会触发事件。 活动session获取到提示事件。

0x01常用Linux命令

常用Linux命令

1. 用wget下载oracle jdk

1
2
3
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u65-b17/jdk-8u65-linux-x64.tar.gz

2.代码行数统计

1
2
3
4
find . -name "*.java"|xargs cat|grep -v -e ^$ -e ^\s*\/\/.*$|wc -l
find . "(" -name "*.java" ")" -print | xargs wc -l
find . -name "*.java"|xargs cat|wc -l

3.安装jdk并绑定命令行

解压JDK安装包,使用update-alternatives 来绑定命令行

1
2
#update-alternatives --install /usr/bin/java java /usr/java/java7/bin/java 1100  
#update-alternatives --install /usr/bin/javac javac /usr/java/java7/bin/javac 1100

如果存在多个,可以使用,来修改默认java对应的链接:

1
# update-alternatives --config java 

4.nginx黑名单

1
tail -n50000 /var/log/nginx/access.log |awk '{print $1,$7,$9}' |grep -i -v -E "google|yahoo|baidu|msnbot|FeedSky|sogou|360|bing|soso|403|api" |awk '{print $1}'|sort|uniq -c|sort -rn|awk '{if($1>1000)print "deny "$2";"}' > /etc/nginx/conf.d/blockip.conf
1
tail -n50000 /var/log/nginx/access.log |awk '{print $1}'|sort|uniq -c|sort -rn

5.tail 加上过滤参数

1
tail -f www.jiangren.us_access.log | grep --line-buffered "jd_attack_test"

6.查看操作系统版本及基本信息

1
2
3
4
cat /etc/issue
lsb_release -a
cat /proc/version
uname -a

7.占用端口进程查询

- windows 下占用端口查询以及关闭

查询端口占用的进程ID
netstat -ano 各个端口占用和进程PID
netstat -aon | findstr “80”

1
2
 C:\Users\admin>netstat -aon|findstr "80"
TCP 127.0.0.1:9080 0.0.0.0:0 LISTENING 4632

查看端口号所对应的应用程序

1
2
tasklist | findstr "  4632" 
GROOVE.EXE 4632 Console 1 84,880 K

很明显,是GROOVE.EXE 占用了80端口,GROOVE.EXE 一个IE的ACTIVEX控件。

终止进程

1
taskkill /pid 4632 /F 

或则使用 taskkill /f /t /im GROOVE.exe

- linux下占用端口查询以及关闭

查询端口号占用,根据端口查看进程信息

1
2
3
[root@server2 ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
httpd 5014 root 3u IPv4 14346 TCP server2:http (LISTEN)

根据进程号查看进程对应的可执行程序
ps -f -p 进程号

1
2
3
ps -f -p 5014
UID PID PPID C STIME TTY TIME CMD
root 5014 1 0 17:26 ? 00:00:00 /usr/local/apache/bin/httpd -k

根据可执行程序查看动态链接
ldd 可执行文件名

1
2
3
ldd  /usr/local/apache/bin/httpd
linux-vdso.so.1 => (0x00007fff9dc90000)
libaprutil-0.so.0 => /usr/local/apache/lib/libaprutil-0.so.0 (0x00002af026fcd000)

根据端口号得到其占用的进程的详细信息

1
2
3
netstat -tlnp|grep 80
tcp 0 0 192.168.33.10:80 0.0.0.0:* LISTEN 5014/httpd
tcp 0 0 0.0.0.0:48054 0.0.0.0:* LISTEN 5386/java

一次性的清除占用80端口的程序
`lsof -i :80|grep -v “PID”|awk ‘{print “kill -9”,$2}’|sh

手工终止进程的运行
kill 5014如果终止不了,可以强制终止kill -9 5014

8.ssh 免密码登录

使用ssh-keygen生成秘钥,然后把公钥(id_rsa.pub)复制到远程机器上(~/.ssh/authorized_keys)。

1
2
ssh-keygen
ssh-copy-id user@host

如果还是不行,需要输入密码,就打开远程主机的/etc/ssh/sshd_config这个文件,检查下面几行前面”#”注释是否取掉。

1
2
3
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

如果还是不行,加上调试参数ssh root@ip -vv,查看什么地方不行

1
2
3
4
5
6
7
8
9
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/felix021/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/felix021/.ssh/id_dsa
debug1: Trying private key: /home/felix021/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug1: Next authentication method: password

具体是什么问题,可以在远程机器上通过执行 /usr/sbin/sshd -d -p 2222 (在2222端口启动一个带debug输出的sshd) ,然后 ssh root@ip -vv -p 2222 ,可以看到在远程机器上sshd输出了一行

1
Authentication refused: bad ownership or modes for directory /root

这时候就可以基本确定是由于目录权限问题,调整相应目录的权限即可:

1
2
3
chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys