我编写代码从 xml 文件读取和打开 myapp 配置。代码尝试解析文件中的关键元素并在它们不存在时创建它们:
static xmlDocPtr configsave_open( const char *config_filename )
{
xmlDocPtr doc;
xmlNodePtr top;
int create_file = 0;
doc = xmlParseFile( config_filename );
......................................
xmlKeepBlanksDefault( 0 );
if( create_file ) {
char *temp = strdup( config_filename ); /* <-- crashed with SIGSEGV in __GI___strdup() */
if( ! temp ) {
fprintf( stderr, "strdup failed for config_filename %s\n", config_filename );
xmlFreeDoc( doc );
return 0;
}
mkdir_and_force_owner( dirname( temp ), getuid(), getgid() );
free( temp );
}
......................................
return doc;
}
我写测试用例:
#!/bin/bash
# seed id: 16154
DIR="$( cd "$( dirname "$0" )" && pwd )"
GDB=
if [ "$1" = "-g" ]
then
GDB="gdb --args"
fi
env -i \
MALLOC_CHECK_=0 \
$GDB \
/usr/bin/myapp \
"`cat $DIR/argv_1.symb`" \
"`cat $DIR/argv_2.symb`" \
\
< "$DIR/file___dev__stdin.symb"
exit_code=$?
exit $exit_code
其中 argv_2.symb 文件包含:
'`
和 file__ dev _stdin.symb 包含:
AAAAAAAAAAAAAAAAAAAAAAAA
崩溃输出:
I/O warning : failed to load external entity "NULL"
./exploit.sh: line 19: 7175 Segmentation fault
(core dumped)
env -i MALLOC_CHECK_=0 $GDB /usr/bin/myapp "`cat $DIR/argv_1.symb`" "`cat $DIR/argv_2.symb`" < "$DIR/file___dev__stdin.symb"
尝试使用配置文件参数运行 myapp 时基本崩溃:
/usr/bin/myapp --configfile '`
欢迎任何帮助解决这个问题