C++暴力破解程序非常慢

发布于 2024-12-21 17:16:17 字数 943 浏览 0 评论 0原文

我有一个黑盒程序“secret.exe”,它接受一个数字作为参数。它只接受一个我不知道的数字。我想进行暴力攻击以获得该数字。 下面的 C++ 程序可以做到这一点,但速度相当慢(每秒 13 个数字)。该程序几乎不消耗CPU和内存。 瓶颈是什么? popen 函数速度慢吗?

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
       char psBuffer[128];
       FILE *chkdsk;
       bool nomatch = true;
       int i = 0;
       char cmd[100];
       while(nomatch){
           sprintf (cmd, "secret.exe %d", i++);
           if( (chkdsk = popen( cmd, "rt" )) == NULL )
              cout << "error";
           while( !feof( chkdsk ) ) {
              if( fgets( psBuffer, 128, chkdsk ) != NULL && strcmp(psBuffer, "wrong")){
                  cout << "password: " << --i << endl;
                  cout << "secret info : " << psBuffer << endl;
                  nomatch = false;
              }
           }
           pclose( chkdsk );
       }
      return 0;
}

I got a blackbox program "secret.exe" that accepts a number as an argument. It only accepts one number that I don't know. I want to do a brute force attack to get that number.
The C++-program below does that but is pretty slow (13 numbers per second). CPU and memory are nearly not consumed by this program.
What is the bottleneck? Is the popen-function to slow?

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
       char psBuffer[128];
       FILE *chkdsk;
       bool nomatch = true;
       int i = 0;
       char cmd[100];
       while(nomatch){
           sprintf (cmd, "secret.exe %d", i++);
           if( (chkdsk = popen( cmd, "rt" )) == NULL )
              cout << "error";
           while( !feof( chkdsk ) ) {
              if( fgets( psBuffer, 128, chkdsk ) != NULL && strcmp(psBuffer, "wrong")){
                  cout << "password: " << --i << endl;
                  cout << "secret info : " << psBuffer << endl;
                  nomatch = false;
              }
           }
           pclose( chkdsk );
       }
      return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞旧 2024-12-28 17:16:17

您必须进行基准测试/分析才能找到答案,但 secret.exe 完全有可能只是浪费时间。

You'll have to benchmark/profile to find out, but it's entirely possible that secret.exe just wastes time.

戈亓 2024-12-28 17:16:17

Windows 在进程创建方面效率极低。你可能会在 Linux 上尝试 Wine,但我不知道假装会浪费多少 Linux 的效率是Windows。如果您愿意进行一些挖掘和丑陋的黑客攻击,您可能能够在进程中加载​​并运行相关代码,但此时,您可能最好尝试反汇编/反编译它。

Windows is hideously inefficient at process creation. You might try Wine on Linux, but I don't know how much of Linux's efficiency will be wasted by pretending to be Windows. If you're willing to do some digging and ugly hacks, you might be able to load and run the relevant code in your process, but at that point, you're probably better off trying to disassemble/decompile it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文