您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“基于docker的自制蜜罐怎么實(shí)現(xiàn)”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
捕捉到的東西地址
https://github.com/yingshang/Legacy-of-intrusion.git
蜜罐地址
https://github.com/yingshang/honeypot.git
我發(fā)現(xiàn)使用docker去搞蜜罐是一種挺不錯(cuò)的選擇,相對(duì)于說什么低交互,中交互的蜜罐系統(tǒng)來說,簡直無敵。首先起碼可以在安全性能夠得到保障,假如被人逃逸了,瞬間就有CVE了。
我聊聊一下蜜罐的架構(gòu),一般來說,在整個(gè)互聯(lián)網(wǎng)中存在太多掃描器,一部分是爆破服務(wù),一部分是exp漏洞,那么首先我們要考慮收益的問題,也就是我要攻擊者能夠很快的攻擊到我的蜜罐系統(tǒng),進(jìn)而留下攻擊痕跡,讓我去分析和溯源,進(jìn)而建立攻擊模型。
所以我選擇ssh和mysql設(shè)置弱密碼,讓黑客進(jìn)行暴力破解進(jìn)來。在一個(gè)月前,我分別在不同區(qū)域設(shè)置了蜜罐系統(tǒng),讓我驚訝的是,在同一天我居然捕捉到相同的攻擊樣本。在這個(gè)過程中,外網(wǎng)攻擊的流程一般是使用工具爆破成功后上傳樣本(挖礦,ddos病毒,自我復(fù)制病毒等)。
安裝ssh的時(shí)候,我對(duì)源碼進(jìn)行一些修改,用來記錄攻擊者爆破的密碼
Mar 29 10:57:09 85740b4003de sshd[120]: Username: root, Password: 123123 Mar 29 10:57:09 85740b4003de sshd[120]: Failed password for root from 174.138.56.93 port 45482 ssh3 Mar 29 10:57:09 85740b4003de sshd[120]: error: Received disconnect from 174.138.56.93: 11: Normal Shutdown, Thank you for playing Mar 29 10:57:23 85740b4003de sshd[121]: error: Received disconnect from 223.111.139.211: 11: Mar 29 10:57:58 85740b4003de sshd[122]: error: Received disconnect from 222.186.30.71: 11: Mar 29 10:58:49 85740b4003de sshd[123]: Invalid user ubuntu from 159.89.116.97 Mar 29 10:58:49 85740b4003de sshd[123]: input_userauth_request: invalid user ubuntu Mar 29 10:58:49 85740b4003de sshd[123]: Username: ubuntu, Password: ubuntu123 Mar 29 10:58:49 85740b4003de sshd[123]: error: Could not get shadow information for NOUSER Mar 29 10:58:49 85740b4003de sshd[123]: Failed password for invalid user ubuntu from 159.89.116.97 port 57664 ssh3 Mar 29 10:58:49 85740b4003de sshd[123]: error: Received disconnect from 159.89.116.97: 11: Normal Shutdown, Thank you for playing Mar 29 11:02:07 85740b4003de sshd[124]: Invalid user oracle from 46.105.30.20 Mar 29 11:02:07 85740b4003de sshd[124]: input_userauth_request: invalid user oracle Mar 29 11:02:07 85740b4003de sshd[124]: Username: oracle, Password: qwe@123 Mar 29 11:02:07 85740b4003de sshd[124]: error: Could not get shadow information for NOUSER Mar 29 11:02:07 85740b4003de sshd[124]: Failed password for invalid user oracle from 46.105.30.20 port 42954 ssh3 Mar 29 11:02:08 85740b4003de sshd[124]: error: Received disconnect from 46.105.30.20: 11: Normal Shutdown, Thank you for playing Mar 29 11:03:46 85740b4003de sshd[125]: Invalid user support from 103.120.226.12 Mar 29 11:03:46 85740b4003de sshd[125]: input_userauth_request: invalid user support Mar 29 11:03:46 85740b4003de sshd[125]: Username: support, Password: password Mar 29 11:03:46 85740b4003de sshd[125]: error: Could not get shadow information for NOUSER Mar 29 11:03:46 85740b4003de sshd[125]: Failed password for invalid user support from 103.120.226.12 port 48932 ssh3 Mar 29 11:03:46 85740b4003de sshd[125]: error: Received disconnect from 103.120.226.12: 11: Normal Shutdown, Thank you for playing Mar 29 11:05:17 85740b4003de sshd[126]: error: Received disconnect from 36.156.24.94: 11: Mar 29 11:06:15 85740b4003de sshd[127]: Username: root, Password: uClinux Mar 29 11:06:15 85740b4003de sshd[127]: Failed password for root from 95.189.253.93 port 59721 ssh3 Mar 29 11:06:16 85740b4003de sshd[127]: Username: root, Password: root Mar 29 11:06:16 85740b4003de sshd[127]: Failed password for root from 95.189.253.93 port 59721 ssh3 Mar 29 11:06:16 85740b4003de sshd[127]: Username: root, Password: system Mar 29 11:06:16 85740b4003de sshd[127]: Failed password for root from 95.189.253.93 port 59721 ssh3 Mar 29 11:06:16 85740b4003de sshd[127]: Username: root, Password: 123456 Mar 29 11:06:16 85740b4003de sshd[127]: Accepted password for root from 95.1
還有我在history那里埋了個(gè)點(diǎn)
PS1="`whoami`@`hostname`:"'[$PWD]' history USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` if [ "$USER_IP" = "" ] then USER_IP=`hostname` fi if [ ! -d /usr/operation ] then mkdir /usr/operation chmod 777 /usr/operation fi if [ ! -d /usr/operation/${LOGNAME} ] then mkdir /usr/operation/${LOGNAME} chmod 300 /usr/operation/${LOGNAME} fi export HISTSIZE=4096 DT=`date "+%Y-%m-%d_%H:%M:%S"` if [ ! -d /usr/operation/${LOGNAME}/${USER_IP} ] then mkdir /usr/operation/${LOGNAME}/${USER_IP} chmod 300 /usr/operation/${LOGNAME}/${USER_IP} fi export HISTFILE="/usr/operation/${LOGNAME}/${USER_IP}/$DT" chmod 600 /usr/operation/${LOGNAME}/${USER_IP}/** 2>/dev/null
操作日志
root@85740b4003de:/# cd /usr/operation/root/185.234.217.217/ root@85740b4003de:/usr/operation/root/185.234.217.217# ls 2019-03-29_11:06:19 root@85740b4003de:/usr/operation/root/185.234.217.217# cat 2019-03-29_11\:06\:19 /gisdfoewrsfdf sudo /bin/sh root@85740b4003de:/usr/operation/root/185.234.217.217#
接著我在dockerfile設(shè)置ssh和mysql的密碼是123456,不過我沒有開啟mysql日志記錄,主要是我懶~~~~~~~有空在搞
其實(shí)在一開始上面這樣已經(jīng)完結(jié)的,因?yàn)楣粽叩娜罩緯?huì)通過history來記錄,但是后來發(fā)現(xiàn)還是太年輕了,像這種使用腳本ssh進(jìn)來的是不會(huì)留有history日志的。所以我進(jìn)行了改進(jìn),干脆監(jiān)控全局的變化,想到用ossec,但是發(fā)現(xiàn)太過笨重了,于是就用python寫了個(gè)監(jiān)控腳本用來監(jiān)控攻擊者的行為和保存攻擊樣本。
import os import datetime import pyinotify import logging import shutil import random import hashlib import string import sys path = "/usr/share/record/file/" def mylog(): # 創(chuàng)建一個(gè)日志記錄器 log = logging.getLogger("test_logger") log.setLevel(logging.INFO) # 創(chuàng)建一個(gè)日志處理器 ## 這里需要正確填寫路徑和文件名,拼成一個(gè)字符串,最終生成一個(gè)log文件 logHandler = logging.FileHandler(filename ="/usr/share/record/error.log") ## 設(shè)置日志級(jí)別 logHandler.setLevel(logging.INFO) # 創(chuàng)建一個(gè)日志格式器 formats = logging.Formatter('%(asctime)s %(levelname)s: %(message)s', datefmt='[%Y/%m/%d %I:%M:%S]') # 將日志格式器添加到日志處理器中 logHandler.setFormatter(formats) # 將日志處理器添加到日志記錄器中 log.addHandler(logHandler) return log def GetFileMd5(filename): if not os.path.isfile(filename): return myhash = hashlib.md5() f = open(filename,'rb') while True: b = f.read(8096) if not b : break myhash.update(b) f.close() return myhash.hexdigest() def filecp(source,name,type): day_name = path + datetime.datetime.now().strftime('%Y%m%d') hour_name = day_name+'/' + datetime.datetime.now().strftime('%H') if not os.path.exists(day_name): os.mkdir(day_name) if not os.path.exists(hour_name): os.mkdir(hour_name) try: source_md5 = GetFileMd5(source) status = 0 for root, dirs, files in os.walk(path, topdown=False): for i in files: file_md5 = GetFileMd5(os.path.join(root, i)) if file_md5 == source_md5: status = 1 if status ==0: fsize = int(os.path.getsize(source)) if fsize != 0: now = datetime.datetime.now().strftime("%M-%S") token = ''.join(random.sample(string.ascii_letters + string.digits, 8)) shutil.copy(source,hour_name+'/'+name + "_" +token+"_"+now+"_"+type) except FileNotFoundError: pass except OSError: pass class MyEventHandler(pyinotify.ProcessEvent): logging.basicConfig(level=logging.INFO, filename='/usr/share/record/monitor.log') logging.info("Starting monitor...") def process_IN_ACCESS(self, event): print("ACCESS event:", event.pathname) logging.info("ACCESS event : %s %s" % (os.path.join(event.path, event.name), datetime.datetime.now())) def process_IN_ATTRIB(self, event): print("ATTRIB event:", event.pathname) logging.info("IN_ATTRIB event : %s %s" % (os.path.join(event.path, event.name), datetime.datetime.now())) # filecp(source=os.path.join(event.path, event.name),name=event.name,type="ATTRIB") # def process_IN_CLOSE_NOWRITE(self, event): # print("CLOSE_NOWRITE event:", event.pathname) # logging.info("CLOSE_NOWRITE event : %s %s" % (os.path.join(event.path, event.name), datetime.datetime.now())) # def process_IN_CLOSE_WRITE(self, event): # print("CLOSE_WRITE event:", event.pathname) # logging.info("CLOSE_WRITE event : %s %s" % (os.path.join(event.path, event.name), datetime.datetime.now())) # filecp(source=os.path.join(event.path, event.name),name=event.name,type="CLOSE_WRITE") def process_IN_CREATE(self, event): print("CREATE event:", event.pathname) logging.info("CREATE event : %s %s" % (os.path.join(event.path, event.name), datetime.datetime.now())) filecp(source=os.path.join(event.path, event.name),name=event.name,type="CREATE") def process_IN_DELETE(self, event): print("DELETE event:", event.pathname) logging.info("DELETE event : %s %s" % (os.path.join(event.path, event.name), datetime.datetime.now())) #filecp(source=os.path.join(event.path, event.name),name=event.name,type="DELETE") def process_IN_MODIFY(self, event): print("MODIFY event:", event.pathname) logging.info("MODIFY event : %s %s" % (os.path.join(event.path, event.name), datetime.datetime.now())) if event.name != "null": filecp(source=os.path.join(event.path, event.name), name=event.name, type="MODIFY") def process_IN_OPEN(self, event): print("OPEN event:", event.pathname) logging.info("OPEN event : %s %s" % (os.path.join(event.path, event.name), datetime.datetime.now())) def main(): # watch manager excl_list = [ '/usr/share/record', '/var/log', ] excl = pyinotify.ExcludeFilter(excl_list) wm = pyinotify.WatchManager() wm.add_watch('/tmp', pyinotify.ALL_EVENTS, rec=True,exclude_filter=excl) eh = MyEventHandler() # notifier logger = mylog() try: notifier = pyinotify.Notifier(wm, eh) notifier.loop() except : logger.exception(sys.exc_info()) logger.info("Error in log") if __name__ == '__main__': main()
下面是監(jiān)控的日志
INFO:root:OPEN event : /tmp/hsperfdata_root 2019-03-25 06:27:05.780024 INFO:root:ACCESS event : /tmp/hsperfdata_root 2019-03-25 06:27:05.780818 INFO:root:CREATE event : /tmp/2tk8gg28p1pkzsc4i088gdu4zl 2019-03-25 12:07:45.775160 INFO:root:OPEN event : /tmp/2tk8gg28p1pkzsc4i088gdu4zl 2019-03-25 12:07:45.935427 INFO:root:MODIFY event : /tmp/2tk8gg28p1pkzsc4i088gdu4zl 2019-03-25 12:07:46.179364 INFO:root:OPEN event : /tmp/2tk8gg28p1pkzsc4i088gdu4zl 2019-03-25 12:07:46.357906 INFO:root:ACCESS event : /tmp/2tk8gg28p1pkzsc4i088gdu4zl 2019-03-25 12:07:46.358347 INFO:root:OPEN event : /tmp/2tk8gg28p1pkzsc4i088gdu4zl 2019-03-25 12:07:46.358630 INFO:root:ACCESS event : /tmp/2tk8gg28p1pkzsc4i088gdu4zl 2019-03-25 12:07:46.358835 INFO:root:OPEN event : /tmp/2tk8gg28p1pkzsc4i088gdu4zl 2019-03-25 12:07:47.577594 INFO:root:ACCESS event : /tmp/2tk8gg28p1pkzsc4i088gdu4zl 2019-03-25 12:07:47.578082 INFO:root:ACCESS event : /tmp/2tk8gg28p1pkzsc4i088gdu4zl 2019-03-25 12:07:47.578376 INFO:root:DELETE event : /tmp/2tk8gg28p1pkzsc4i088gdu4zl 2019-03-25 12:07:48.699488 INFO:root:CREATE event : /tmp/knrm 2019-03-25 12:07:50.316929 INFO:root:OPEN event : /tmp/knrm 2019-03-25 12:07:50.317885 INFO:root:OPEN event : /tmp/knrm 2019-03-25 12:07:50.318216 INFO:root:MODIFY event : /tmp/knrm 2019-03-25 12:07:51.220061 INFO:root:OPEN event : /tmp/knrm 2019-03-25 12:07:51.221799 INFO:root:ACCESS event : /tmp/knrm 2019-03-25 12:07:51.221942 INFO:root:OPEN event : /tmp/knrm 2019-03-25 12:07:51.222171 INFO:root:ACCESS event : /tmp/knrm 2019-03-25 12:07:51.222359 INFO:root:MODIFY event : /tmp/knrm 2019-03-25 12:07:51.446485 INFO:root:OPEN event : /tmp/knrm 2019-03-25 12:07:51.448138
接下來是安裝和運(yùn)行
docker build -t hon .
運(yùn)行蜜罐
docker run -d -v /record:/usr/share/record -p 22:22 hon
接下來就等攻擊者來,一般512M的VPS都可以帶起來的。
有幾個(gè)構(gòu)想還沒有寫,等有空再寫把,一個(gè)是將蜜罐的日志實(shí)時(shí)傳輸?shù)綄?shí)體機(jī)上面,假如被刪除或者有什么異動(dòng),郵件報(bào)警。另外一個(gè)就是監(jiān)控流量,我有一臺(tái)VPS沒有注意看,病毒直接把我的流量都打光了。
“基于docker的自制蜜罐怎么實(shí)現(xiàn)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。