我需要通过应用程序更改散列部分.
下图是我的影子文件:
运行应用程序后,哈希部分将像下面的图像改变.
下面代码工作,但我需要两件事:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <pwd.h>
int main() {
system("cp /etc/shadow /etc/shadow_old");
FILE* shadow = fopen("/etc/shadow_old","r+");
if (shadow == NULL)
{
printf ("Cannot open shadow file \n");
return -1;
}
char * line = NULL;
size_t len = 0;
char* delimiter= ":";
ssize t read;
int ret = 0;
char key[] = "root:";
char value[] = "M0686fd1d172ba1:!!:118 ..... 9::::";
char* pch = NULL;
while ((read = getline(&line, &len, shadow)) != -1)
{
pch = NULL;
pch = strstr(line, key);
printf("pos: U\n",ftell(shadow));
if(pch)
{
printf("pch--> %s\n",pch);
printf("current password--> %s\n",pch+(strlen(key)+strlen(delimiter)));
fseek(shadow,-strlen(line),SEEK_CUR);
printf("pos after fseek: U\n",ftell(shadow));
break:
}
}
if (line)
{
int lenOfLine=strlen(line);
char* str=(char*) malloc (lenOfLine);
memset(str,' ',lenOfLine);
if(value!=NULL)
{
fwrite(key,1,sizeof(key),shadow);
fwrite(value,1,sizeof(value),shadow);
}
free(str);
}
fclose(shadow);
return 0;
}
1:当我的哈希值小于以前时,哈希值未被完全替换
他说:我需要一个通用的解决方案,我想我的代码是脏的.
谢谢你的广告.赏识