Home > Articles > Security > Network Security

This chapter is from the book

Automatic, Bulk Auditing for Vulnerabilities

Clearly, reverse engineering is a time-consuming task and a process that does not scale well. There are many cases when reverse engineering for security bugs would be valuable, but there isn't nearly enough time to analyze each and every component of a software system the way we have done in the previous section. One possibility, however, is automated analysis. IDA provides a platform for adding your own analysis algorithms. By writing a special script for IDA, we can automate some of the tasks required for finding a vulnerability. Here, we provide an example of strict white box analysis. [14]

Harking back to a previous example, let's assume we want to find other bugs that may involve the (mis)use of wcsncat. We can use a utility called dumpbin under Windows to show which calls are imported by an executable:

dumpbin /imports target.exe

To bulk audit all the executables on a system, we can write a small Perl script. First create a list of executables to analyze. Use the dir command as follows:

dir /B /S c:\winnt\*.exe > files.txt

This creates a large output file of all the executable files under the WINNT directory. The Perl script will then call dumpbin on each file and will analyze the results to determine whether wcsncat is being used:

open(FILENAMES, "files.txt");
while (<FILENAMES>)
    my $filename = $_;
    $command = "dumpbin /imports $_ > dumpfile.txt";
    #print "trying $command";

    open(DUMPFILE, "dumpfile.txt");
    while (<DUMPFILE>)
            print "$filename: $_";

Running this script on a system in the lab produces the following output:

C:\temp>perl scan.pl
c:\winnt\winrep.exe:    7802833F  2E4 wcsncat
c:\winnt\INF\UNREGMP2.EXE:    78028EDD  2E4 wcsncat
c:\winnt\SPEECH\VCMD.EXE:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\dfrgfat.exe:    77F8F2A0  499 wcsncat
c:\winnt\SYSTEM32\dfrgntfs.exe:    77F8F2A0  499 wcsncat
c:\winnt\SYSTEM32\IESHWIZ.EXE:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\NET1.EXE:    77F8E8A2  491 wcsncat
c:\winnt\SYSTEM32\NTBACKUP.EXE:    77F8F2A0  499 wcsncat
c:\winnt\SYSTEM32\WINLOGON.EXE:              2E4 wcsncat

We can see that several of the programs under Windows NT are using wcsncat. With a little time we can audit these files to determine whether they suffer from similar problems to the example program we show earlier. We could also examine DLLs using this method and generate a much larger list:

C:\temp>dir /B /S c:\winnt\*.dll > files.txt

C:\temp>perl scan.pl

c:\winnt\SYSTEM32\AAAAMON.DLL:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\adsldpc.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\avtapi.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\AVWAV.DLL:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\BR549.DLL:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\CMPROPS.DLL:    78028EDD  2E7 wcsncat
c:\winnt\SYSTEM32\DFRGUI.DLL:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\dhcpmon.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\dmloader.dll:              2FB wcsncat
c:\winnt\SYSTEM32\EVENTLOG.DLL:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\GDI32.DLL:    77F8F2A0  499 wcsncat
c:\winnt\SYSTEM32\IASSAM.DLL:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\IFMON.DLL:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\LOCALSPL.DLL:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\LSASRV.DLL:           2E4 wcsncat
c:\winnt\SYSTEM32\mpr.dll:    77F8F2A0  499 wcsncat
c:\winnt\SYSTEM32\MSGINA.DLL:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\msjetoledb40.dll:    7802833F  2E2 wcsncat
c:\winnt\SYSTEM32\MYCOMPUT.DLL:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\netcfgx.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\ntdsa.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\ntdsapi.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\ntdsetup.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\ntmssvc.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\NWWKS.DLL:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\ODBC32.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\odbccp32.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\odbcjt32.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\OIPRT400.DLL:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\PRINTUI.DLL:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\rastls.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\rend.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\RESUTILS.DLL:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\SAMSRV.DLL:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\scecli.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\scesrv.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\sqlsrv32.dll:            2E2 wcsncat
c:\winnt\SYSTEM32\STI_CI.DLL:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\USER32.DLL:    77F8F2A0  499 wcsncat
c:\winnt\SYSTEM32\WIN32SPL.DLL:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\WINSMON.DLL:    78028EDD  2E4 wcsncat
c:\winnt\SYSTEM32\dllcache\dmloader.dll:              2FB wcsncat
c:\winnt\SYSTEM32\SETUP\msmqocm.dll:    7802833F  2E4 wcsncat
c:\winnt\SYSTEM32\WBEM\cimwin32.dll:    7802833F  2E7 wcsncat
c:\winnt\SYSTEM32\WBEM\WBEMCNTL.DLL:    78028EDD  2E7 wcsncat

Batch Analysis with IDA-Pro

We already illustrated how to write a plugin module for IDA. IDA also supports a scripting language. The scripts are called IDC scripts and can sometimes be easier than using a plugin. We can perform a batch analysis with the IDA-Pro tool by using an IDC script as follows:

c:\ida\idaw -Sbatch_hunt.idc -A -c c:\winnt\notepad.exe

with the very basic IDC script file shown here:

#include <idc.idc>
static main(void) {
 /* will hang if existing database file */

As another example, consider batch analysis for sprintf calls. The Perl script calls IDA using the command line:

open(FILENAMES, "files.txt");
while (<FILENAMES>)
    my $filename = $_;
    $command = "dumpbin /imports $_ > dumpfile.txt";
    #print "trying $command";


    open(DUMPFILE, "dumpfile.txt");
    while (<DUMPFILE>)
            print "$filename: $_\n";
            system("c:\\ida\\idaw -Sbulk_audit_sprintf.idc -A -c $filename");

We use the script bulk_audit_sprintf.idc:

//   This example shows how to use GetOperandValue() function.

#include <idc.idc>

/* this routine is hard coded to understand sprintf calls */

static hunt_address(    eb,         /* the address of this call */
                        param_count,  /* the number of parameters for this call */
                        ec,         /* maximum number of instructions to backtrace */
    auto ep; /* placeholder */
    auto k;
    auto kill_frame_sz;
    auto comment_string;

    k = GetMnem(eb);

    if(strstr(k, "call") != 0)
        Message("Invalid starting point\n");

    /* backtrace code */
    while( eb=FindCode(eb, 0) )
        auto j;
        j = GetMnem(eb);

        /* exit early if we run into a retn code */
        if(strstr(j, "retn") == 0) return;

        /* push means argument to sprintf call */
        if(strstr(j, "push") == 0)
            auto my_reg;
            auto max_backtrace;

            ep = eb; /* save our place */

            /* work back to find out the parameter */
            my_reg = GetOpnd(eb, 0);
            fprintf(output_file, "push number %d, %s\n", param_count, my_reg);

            max_backtrace = 10; /* don't backtrace more than 10 steps */
                auto x;
                auto y;

                eb = FindCode(eb, 0); /* backwards */
                x = GetOpnd(eb,0);
                if ( x != -1 )
                    if(strstr(x, my_reg) == 0)
                        auto my_src;
                        my_src = GetOpnd(eb, 1);

                        /* param 3 is the target buffer */
                        if(3 == param_count)
                            auto my_loc;
                            auto my_sz;
                            auto frame_sz;

                            my_loc = PrevFunction(eb);

                            fprintf(output_file, "detected
                                subroutine 0x%x\n", my_loc);

                            my_sz = GetFrame(my_loc);
                            fprintf(output_file, "got frame
                            %x\n", my_sz);

                            frame_sz = GetFrameSize(my_loc);
                            fprintf(output_file, "got frame size
                                %d\n", frame_sz);

                            kill_frame_sz =
                            fprintf(output_file, "got frame lvar
                                size %d\n", kill_frame_sz);

                            my_sz = GetFrameArgsSize(my_loc);
                            fprintf(output_file, "got frame args
                                size %d\n", my_sz);

                            /* this is the target buffer */
                            fprintf(output_file, "%s is the target buffer,
                                in frame size %d bytes\n",
                                my_src, frame_sz);

                        /* param 1 is the source buffer */
                        if(1 == param_count)
                            fprintf(output_file, "%s is the source buffer\n",
                            if(-1 != strstr(my_src, "arg"))
                                fprintf(output_file, "%s is an argument that will
                                    overflow if larger than %d bytes!\n",
                                    my_src, kill_frame_sz);
                if(max_backtrace == 0)break;
            eb = ep; /* reset to where we started and continue for next parameter */
            if(0 == param_count)
                    fprintf(output_file, "Exhausted all  parameters\n");
        if(ec-- == 0)break; /* max backtrace looking for parameters */

static main()
    auto ea;
    auto eb;
    auto last_address;
    auto output_file;
    auto file_name;

    /* turn off all dialog boxes for batch processing */
    /* wait for autoanalysis to complete */

    ea = MinEA();
    eb = MaxEA();

    output_file = fopen("report_out.txt", "a");
    file_name = GetIdbPath();

    fprintf(output_file, "----------------------------------------------\nFilename: %s\n",
ccc.gif file_name);
   fprintf(output_file, "HUNTING FROM %x TO %x
   ccc.gif\n----------------------------------------------\n", ea, eb);
   while(ea != BADADDR)
   auto my_code;
   //Message("checking %x\n", ea);
   my_code = GetMnem(ea);
   if(0 == strstr(my_code, "call")){
   auto my_op;
   my_op = GetOpnd(ea, 0);
   if(-1 != strstr(my_op, "sprintf")){
   fprintf(output_file, "Found sprintf call at 0x%x -
   checking\n", ea);
   /* 3 parameters, max backtrace of 20 */
   hunt_address(ea, 3, 20, output_file);
   fprintf(output_file, "------------------------------------
   ea = FindCode(ea, 1);
   fprintf(output_file, "FINISHED at address 0x%x
   ccc.gif\n----------------------------------------------\n", last_address);

The output produced by this simple batch file is placed in a file called report_out.txt for later analysis. The file looks something like this:

Filename: C:\reversing\of1.idb
HUNTING FROM 401000 TO 404000
Found sprintf call at 0x401012 - checking
push number 3, ecx
detected subroutine 0x401000

got frame ff00004f
got frame size 32
got frame lvar size 28
got frame args size 0
[esp+1Ch+var_1C] is the target buffer, in frame size 32 bytes
push number 2, offset unk_403010
push number 1, eax
[esp+arg_0] is the source buffer
[esp+arg_0] is an argument that will overflow if larger than 28 bytes!
Exhausted all parameters
Found sprintf call at 0x401035 - checking
push number 3, ecx
detected subroutine 0x401020
got frame ff000052
got frame size 292
got frame lvar size 288
got frame args size 0
[esp+120h+var_120] is the target buffer, in frame size 292 bytes
push number 2, offset aSHh
push number 1, eax
[esp+arg_0] is the source buffer
[esp+arg_0] is an argument that will overflow if larger than 288 bytes!
Exhausted all parameters
FINISHED at address 0x4011b6
Filename: C:\winnt\MSAGENT\AGENTCTL.idb
HUNTING FROM 74c61000 TO 74c7a460
Found sprintf call at 0x74c6e3b6 - checking
push number 3, eax
detected subroutine 0x74c6e2f9
got frame ff000eca
got frame size 568
got frame lvar size 552
got frame args size 8
[ebp+var_218] is the target buffer, in frame size 568 bytes
push number 2, offset aD__2d
push number 1, eax
[ebp+var_21C] is the source buffer
Exhausted all parameters

Searching the function calls, we see a suspect call to lstrcpy(). Analyzing lots of code automatically is a common trick to look for good starting places, and it turns out to be very useful in practice.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020