當前位置:編程學習大全網 - 源碼下載 - 在c\c++程序裏怎麽執行shell腳本命令?

在c\c++程序裏怎麽執行shell腳本命令?

在C/C++源碼中執行shell命令,最基本的就是 system() C庫函數,其次可以使用系統提供的api函數,比如windows上的createprocess shellexecuteex等函數,在linux上可以使用exec()等等.

下面是我在windows上的弄的壹個測試版本,使用了線程,我感覺用nc來測試,不如直接 netstat -an | findstr /I "udp" | findstr "22" ,因為22端口太其特了,很容易抓出來. 另外nc判斷端口常規的作法就是 nc -vv ip port 看提示信息就好了.

#include <stdio.h>

#include <stdlib.h>

#include <tchar.h>

#include <windows.h>

#include <process.h>

UINT __stdcall ThreadFunc(LPVOID lpParam) {

//將hacker字符串做為nc提交的數據

int ret = system("echo hacker | nc.exe -u 127.1 22");

//ret==0說明沒有開啟22端口

if (ret == 0 ) printf("nc: Write error: Connection refused.\n");

return 0;

}

int main()

{

HANDLE hThread = (HANDLE)_beginthreadex(0, 0, ThreadFunc, 0, 0, 0);

//等待3秒鐘,說明22端口可用

WaitForSingleObject(hThread, 3000);

//結束測試線程

TerminateThread(hThread, 0);

//重新開啟NC連接22端口

system("nc.exe -vv -u 127.1 22");

return 0;

}

歡迎光臨0x30貼吧,壹個高質量的計算機技術交流平臺.

  • 上一篇:<蓋世英雄>裏面歌的歌詞,個個網站也行
  • 下一篇:私有域流量如何運營,私有域流量運營有哪些工具?
  • copyright 2024編程學習大全網