IDAPython 1.5.4

- fix for Python autorun script vulnerability reported by Greg MacManus
- remove current directory from sys.path during initialization
This commit is contained in:
skochinsky@gmail.com 2012-03-26 13:39:09 +00:00
parent 06f0ff19d5
commit 0282e67982
6 changed files with 78 additions and 20 deletions

View File

@ -1,6 +1,16 @@
Please see http://code.google.com/p/idapython/source/list for a detailed list of changes. Please see http://code.google.com/p/idapython/source/list for a detailed list of changes.
Changes from version 1.5.3 to 1.5.4
------------------------------------
- fix for Python autorun script vulnerability reported by Greg MacManus
- remove current directory from sys.path during initialization
- added PyWraps sources. This will facilitate deployment, development and
debugging of IDAPython additions
- bugfix: op_t.is_reg() was buggy
- bugfix: build.py was putting duplicate files into the .zip
- bugfix: added back wrapped version of get_ascii_contents()
Changes from version 1.5.2 to 1.5.3 Changes from version 1.5.2 to 1.5.3
------------------------------------ ------------------------------------
- IDA Pro 6.2 support - IDA Pro 6.2 support

View File

@ -36,7 +36,7 @@ else:
# IDAPython version # IDAPython version
VERSION_MAJOR = 1 VERSION_MAJOR = 1
VERSION_MINOR = 5 VERSION_MINOR = 5
VERSION_PATCH = 3 VERSION_PATCH = 4
# Determine Python version # Determine Python version
PYTHON_MAJOR_VERSION = int(platform.python_version()[0]) PYTHON_MAJOR_VERSION = int(platform.python_version()[0])

View File

@ -1265,6 +1265,29 @@ static int idaapi menu_installer_cb(void *, int code, va_list)
return 0; return 0;
} }
//-------------------------------------------------------------------------
// remove current directory (empty entry) from the sys.path
static void sanitize_path()
{
char buf[QMAXPATH];
qstrncpy(buf, Py_GetPath(), sizeof(buf));
char *ctx;
qstring newpath;
for ( char *d0 = qstrtok(buf, DELIMITER, &ctx);
d0 != NULL;
d0 = qstrtok(NULL, DELIMITER, &ctx) )
{
if ( d0[0] == '\0' )
// skip empty entry
continue;
if ( !newpath.empty() )
newpath.append(DELIMITER);
newpath.append(d0);
}
PySys_SetPath(newpath.begin());
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Initialize the Python environment // Initialize the Python environment
bool IDAPython_Init(void) bool IDAPython_Init(void)
@ -1280,7 +1303,7 @@ bool IDAPython_Init(void)
if ( !CheckScriptFiles() ) if ( !CheckScriptFiles() )
return false; return false;
char tmp[MAXSTR+64]; char tmp[QMAXPATH];
#ifdef __LINUX__ #ifdef __LINUX__
// Export symbols from libpython to resolve imported module deps // Export symbols from libpython to resolve imported module deps
qsnprintf(tmp, sizeof(tmp), "libpython%d.%d.so.1", qsnprintf(tmp, sizeof(tmp), "libpython%d.%d.so.1",
@ -1319,10 +1342,9 @@ bool IDAPython_Init(void)
read_user_config_file("python.cfg", set_python_options, NULL); read_user_config_file("python.cfg", set_python_options, NULL);
if ( g_alert_auto_scripts ) if ( g_alert_auto_scripts )
{ {
const char *autofn = pywraps_check_autoscripts(); if ( pywraps_check_autoscripts(tmp, sizeof(tmp))
if ( autofn != NULL
&& askyn_c(0, "HIDECANCEL\nTITLE IDAPython\nThe script '%s' was found in the current directory and will be automatically executed by Python.\n\n" && askyn_c(0, "HIDECANCEL\nTITLE IDAPython\nThe script '%s' was found in the current directory and will be automatically executed by Python.\n\n"
"Do you want to continue loading IDAPython?", autofn) == 0 ) "Do you want to continue loading IDAPython?", tmp) <= 0 )
{ {
return false; return false;
} }
@ -1336,6 +1358,8 @@ bool IDAPython_Init(void)
return false; return false;
} }
sanitize_path();
// Enable multi-threading support // Enable multi-threading support
if ( !PyEval_ThreadsInitialized() ) if ( !PyEval_ThreadsInitialized() )
PyEval_InitThreads(); PyEval_InitThreads();

View File

@ -227,7 +227,7 @@ bool pywraps_nw_notify(int slot, ...);
bool pywraps_nw_init(); bool pywraps_nw_init();
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
const char *pywraps_check_autoscripts(); bool pywraps_check_autoscripts(char *buf, size_t bufsize);
// [De]Initializes PyWraps // [De]Initializes PyWraps
bool init_pywraps(); bool init_pywraps();

View File

@ -94,11 +94,18 @@ struct py_timer_ctx_t
}; };
//------------------------------------------------------------------------ //------------------------------------------------------------------------
const char *pywraps_check_autoscripts() bool pywraps_check_autoscripts(char *buf, size_t bufsize)
{ {
static const char *exts[] = {"py", "pyw", "pyc", "pyo"}; static const char *const exts[] =
{
"py",
"pyc",
"pyd",
"pyo",
"pyw",
};
static const char *fns[] = static const char *const fns[] =
{ {
"swig_runtime_data" SWIG_RUNTIME_VERSION, "swig_runtime_data" SWIG_RUNTIME_VERSION,
"sitecustomize", "sitecustomize",
@ -110,12 +117,17 @@ const char *pywraps_check_autoscripts()
for ( size_t iext=0; iext < qnumber(exts); ++iext ) for ( size_t iext=0; iext < qnumber(exts); ++iext )
{ {
static char fn[QMAXPATH]; static char fn[QMAXPATH];
qsnprintf(fn, sizeof(fn), "%s.%s", fns[ifn], exts[iext]); qsnprintf(buf, bufsize, "%s.%s", fns[ifn], exts[iext]);
if ( qfileexist(fn) ) if ( qfileexist(fn) )
return fn; return true;
if ( qfileexist(fns[ifn]) )
{
qstrncpy(buf, fns[ifn], bufsize);
return true;
} }
} }
return NULL; }
return false;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------

View File

@ -1289,11 +1289,18 @@ struct py_timer_ctx_t
}; };
//------------------------------------------------------------------------ //------------------------------------------------------------------------
const char *pywraps_check_autoscripts() bool pywraps_check_autoscripts(char *buf, size_t bufsize)
{ {
static const char *exts[] = {"py", "pyw", "pyc", "pyo"}; static const char *const exts[] =
{
"py",
"pyc",
"pyd",
"pyo",
"pyw",
};
static const char *fns[] = static const char *const fns[] =
{ {
"swig_runtime_data" SWIG_RUNTIME_VERSION, "swig_runtime_data" SWIG_RUNTIME_VERSION,
"sitecustomize", "sitecustomize",
@ -1305,12 +1312,17 @@ const char *pywraps_check_autoscripts()
for ( size_t iext=0; iext < qnumber(exts); ++iext ) for ( size_t iext=0; iext < qnumber(exts); ++iext )
{ {
static char fn[QMAXPATH]; static char fn[QMAXPATH];
qsnprintf(fn, sizeof(fn), "%s.%s", fns[ifn], exts[iext]); qsnprintf(buf, bufsize, "%s.%s", fns[ifn], exts[iext]);
if ( qfileexist(fn) ) if ( qfileexist(fn) )
return fn; return true;
if ( qfileexist(fns[ifn]) )
{
qstrncpy(buf, fns[ifn], bufsize);
return true;
} }
} }
return NULL; }
return false;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------