Skip to content

实现上网功能#278

Open
cdn2021 wants to merge 1 commit into
monyhar:masterfrom
cdn2021:patch-1
Open

实现上网功能#278
cdn2021 wants to merge 1 commit into
monyhar:masterfrom
cdn2021:patch-1

Conversation

@cdn2021
Copy link
Copy Markdown

@cdn2021 cdn2021 commented Jul 25, 2021

实现上网功能

实现上网功能
@ethushiroha
Copy link
Copy Markdown

ethushiroha commented Aug 5, 2021

url参数存在命令注入

scanf确定没写错吗。。。

@cdn2021
Copy link
Copy Markdown
Author

cdn2021 commented Aug 12, 2021

命令注入.......................................... 懒得写转义
scanf的确有点问题啊,url是一个指针,scanf的值应该存在url指向的字符数组上,而不是存在url上

Copy link
Copy Markdown
Author

@cdn2021 cdn2021 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改后版本(我不是很会用Pull requests功能,就把修改后的代码贴在留言区了)

#include <stdio.h> // printf,scanf 原型
#include <stdlib.h> // malloc,free 原型
#include <string.h> //strcat原型
int surf_internet() {
  while(1){
    printf("URL:");
    char * url = malloc(sizeof(char) * 1024); //1024个字符的url,应该够用了
    if (scanf("%s",url)){
      //读取
      char * command = malloc(sizeof(char) * 1029);
      *command = "curl ";
      strcat(command,url);//拼接
      system(command);//命令行调用
      free(command); //释放内存
      printf("\n");

    };
    free(url);
  return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants