|
我就 修改下登录用户admin的密码,只此一个用户,密码可存的。嵌入式,目标机存储密码(存储方式未知)。
参数化了,原参数 pwd_origin仅设一值,pwd_now也只设一值;每次都把新值写到原值的参数化文件中,以便下次迭代的密码更新;回放完脚本后,迭代2次,模式是sequential/each iteration。跑完,重新登录,密码还是pwd_origin最初的那个值。???????
代码 啰嗦如下,请大虾指教:
web_set_sysuser()
{
long outfread;//A FILE pointer for reading from .dat file
long outfwrite;///A FILE pointer for writing to .dat file
int i =10;
unsigned long status = strlen("{pwd_origin}");
char ch = 'h';//for func:lr_eval_string_ext
const char *file = &ch;//for func:lr_eval_string_ext
char ** const out_str_origin = (char **)malloc(status);//for func:lr_eval_string_ext
char ** const out_str_now = (char **)malloc(status);//for func:lr_eval_string_ext
unsigned long * const out_len = &(status);//for func:lr_eval_string_ext
//replace password decrypted function lr_decrypt with
//C variable(out_str_origin) that received the value of password parameter
//lr_eval_string_ext("{pwd_origin}", status, out_str_origin, out_len, 0, file, -1);
//lr_output_message("!!!!!!!!!!!!current pwd to log---------%s", *out_str_origin);
outfread = fopen("pwd_origin.dat","r");
if( outfread )
{
fseek( outfread, strlen("pwd_origin") + 1, 0 );//指针指向从文件头开始跳过“pwd_origin”所含字节数
//write new value to pwd_origin file, in order to change parameter value
fscanf(outfread, "%s", *out_str_origin);
}
fclose(outfread);//ATTENTION that: close file openned
lr_output_message("!!!!!!!!!!!!current pwd to login---------%s", *out_str_origin);
web_set_user("admin",
*out_str_origin,
"xx.xx.xx.xxx:80");
//lr_decrypt("49cb1f221258746a2be8a5f8"),
lr_output_message("!!!!!!!!!!!!current pwd to login--%p--%s-----%s", "49cb1f221258746a2be8a5f8",lr_decrypt("49cb1f221258746a2be8a5f8"), *out_str_origin);
web_url("xx.xx.xx.xxx",
"URL=http://xx.xx.xx.xxx/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t83.inf",
"Mode=HTML",
EXTRARES,
"Url=/Style_1.css", ENDITEM,
LAST);
web_link("系统管理参数设置",
"Text=系统管理参数设置",
"Snapshot=t84.inf",
LAST);
//submit mew pwd
web_submit_form("sysParamSet",
"Snapshot=t85.inf",
ITEMDATA,
"Name=password1_x", "Value=*out_str_origin", ENDITEM,
"Name=password2_x", "Value={pwd_now}", ENDITEM,
"Name=password3_x", "Value={pwd_now}", ENDITEM,
"Name=configSave", "Value=1", ENDITEM,
"Name=FactoryDefaults", "Value=0", ENDITEM,
"Name=x", "Value=10", ENDITEM,
"Name=y", "Value=12", ENDITEM,
LAST);
status = strlen("{pwd_now}");
lr_eval_string_ext("{pwd_now}", status, out_str_now, out_len, 0, file, -1);
lr_output_message("pwd change to---------%s", *out_str_now);
web_set_user("admin",
*out_str_now,
"xx.xx.xx.xxx:80");
//lr_decrypt("49cb1f221258746a2be8a5f8"),
web_url("xx.xx.xx.xxx",
"URL=http://xx.xx.xx.xxx/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t83.inf",
"Mode=HTML",
EXTRARES,
"Url=/Style_1.css", ENDITEM,
LAST);
web_link("系统管理参数设置",
"Text=系统管理参数设置",
"Snapshot=t84.inf",
LAST);
//We must set the current password to be original, cause the new pwd becomes the login pwd. here tried to rewrite file: pwd_origin.dat.
//NOTE that current pwd will be loaded automatically according to the iteration setting
status = strlen("{pwd_origin}");
lr_eval_string_ext("{pwd_origin}", status, out_str_origin, out_len, 0, file, -1);
/*status = strlen("{pwd_origin}");
lr_eval_string_ext("{pwd_origin}", status, out_str_origin, out_len, 0, file, -1);
lr_output_message("current---------%s", chpwd);*/
/*outfwrite = fopen("pwd_origin.dat", "w+");
//fseek( outfwrite, strlen("pwd_origin") + 1, 0 );//指针指向从文件头开始跳过“pwd_origin”所含字节数
if( outfwrite )// != EOF )
{
//write new value to pwd_origin file, in order to change parameter value
fprintf(outfwrite, "pwd_origin\n%s\n", *out_str_now);
}
fclose(outfwrite);//ATTENTION that to close file openned*/
//ATTENTION to release buffer, otherwise the iteration would take a unit buffer each time
lr_eval_string_ext_free(out_str_origin);
lr_eval_string_ext_free(out_str_now);
return 0;
}
期待 回复。。。。 |
|