Security Testing is a tool for locating XSS,CSRF and SQL Injection vulnerabilities in the Drupal contributed modules. This tool will scans the source code of the contributed module for vulnerabilities and issue warnings. It also tries to exploit XSS vulnerability using SimpleTest module by injecting random data (that will cause XSS) into the database fields of the module and checking if any injected data will come as an output on the screen without sanitizion.It tries to exploit CSRF using SimpleTest by visiting each link of the contributed module and checking if any INSERT,DELETE or UPDATE query runs or not at that link.
Project page :
http://drupal.org/sandbox/udaksh/1611500
Application reviews done::-
http://drupal.org/node/1827294#comment-6670772
http://drupal.org/node/1831082#comment-6689946
http://drupal.org/node/1827958#comment-6671866
http://drupal.org/node/1825780#comment-6661738
More Reviews done :-
http://drupal.org/node/1446848#comment-6772184
http://drupal.org/node/1813730#comment-6770166
http://drupal.org/node/1826640#comment-6773162
More Reviews done :-
http://drupal.org/node/1824770#comment-6882278
http://drupal.org/node/1824770#comment-6885588
http://drupal.org/node/1861942#comment-6885538
http://drupal.org/node/1856530#comment-6885452
http://drupal.org/node/1826272#comment-6885400
Git :
git clone --recursive --branch 7.x-1.x http://git.drupal.org/sandbox/udaksh/1611500.git security_testing
Made for Drupal 7
Comments
Comment #1
ankitchauhan commentedwelcome,
As installation and usage instructions are quite important for us to review, please take a moment to make your project page follow the tips for a great project page. Also make sure your README.txt follows the guidelines for in-project documentation.
while waiting for an in-depht review of your module you can start out fixing some coding style issues detected by automated tools:
http://ventral.org/pareview/httpgitdrupalorgsandboxudaksh1611500git
There is still a master branch, make sure to set the correct default branch: http://drupal.org/node/1659588 . Then remove the master branch, see also step 6 and 7 in http://drupal.org/node/1127732
We do really need more hands in the application queue and highly recommend to get a review bonus so we can come back to your application sooner.
regards
Comment #2
udaksh commentedOk Ankit,
I have removed the master branch and added installation and usage documentation in the project page. I will very soon fix all of the coding style issues.
Thanks
Comment #3
klausiplease get a review bonus first. Then try to fix issues raised by automated review tools and set this back to "needs review".
Comment #4
udaksh commentedI have fixed all the issues raised by automated review tool .
Comment #5
fotuzlab commentedReally well written, readable code. Kudos :)
Need to devote more time for in-depth review, yet the first look of the module is clean and nicely done.
However, I would suggest to go through the naming of form elements again. http://drupal.org/coding-standards#naming.
Its always good to prefix them with your module name, esp. the global variables.
e.g.
$form['location'] (#90 .module) is quite general while $form['mybutton1'] (#95, .module file) is quite vague.
Also better rename menu.inc to security_testing_menu.inc.
Leaving the application in NR status. Hope to see more reviewers chip in.
Comment #6
udaksh commentedHi Fotuzlab ,
Thanks for the review. I have the changed the name of form elements, form.inc file and all global variables as you suggested.
Regards
Comment #6.0
udaksh commentedAdded application reviews done
Comment #6.1
udaksh commentedAdded Review done
Comment #7
udaksh commentedAdded PAReview: review bonus
Comment #7.0
udaksh commentedAdded more application reviews
Comment #8
odegard commentedWow, this looks very promising. This review is just a code review and a cursory one at that. This module need several reviewers because there's a lot to take in.
I've included corrections for some spelling mistakes and comments on readability of variable names. They are not that critical, but I include them as a help if you want it (and my list is probably not complete). Also, I'm new to reviewing so I might go way overboard in some cases. They are not hard recommendations, and I would welcome some comments on my comments as I would learn from it as well.
security_testing.info:
dependencies should be listed (http://drupal.org/node/542202) like this:
dependencies[] = panels
You could also consider adding a link to the config screen in the info files as well like this:
configure = admin/config/content/example
security_testing.install:
Very sparsely commented, but the code is easy to follow so I guess it's ok.
security_testing.module:
Perhaps you should consider making your own set of permissions?
line 104: one to many "from"
line 113: consider adding warning type. I think 'warning' would be appropiate in this case.
line 145-147: you're making some assumptions here that I'm not sure will always work. You're combining all the source files into one big file, remove all instances of '< ?php' and adds a new '< ?php' at the top. Perhaps add a str_replace for '? >' as well? They shouldn't be there... but they might, and that would ruin the php flow.
line 218 and elsewhere: you might want to consider using drupal_basename instead of basename, check this one: http://api.drupal.org/api/drupal/includes!file.inc/function/drupal_basen...
line 273: these two listS (plural), nitpicking, I know ;)
line 323: you're using count($x) inside a for loop. For big $x this can be a performance bottleneck since count($x) is calculated each iteration. Consider adding a $counter before the loop and iterate using that. (Like you're doing on line 335). There are more of these, search for "< count(".
line 355: been -> being
line 450: function security_testing_get_all_callbacks() does a lot of stuff and would benefit from a bit more commenting. Optionally you could consider renaming the variables in lines 487-489 to $check1.. $check3
line 539: Not 100% sure but I think functions should not use camelCase: security_testing_functionCalls() (http://drupal.org/node/1801276)
lines 574->: consider nameng variables more ... describably? $ite, $itemm and $nnode doesn't immediately tell me what they contain making it hard to read since I new to double back once in a while to check "what did that variable containt"?
line 643: I'd really like some more commenting here. Lots of stuff happening, especially in the late 700s/early 800 lines :)
line 656 and others: warning message "[..] is looking to be vulnerable." -> "[..] seems to be vulnerable.""
line 693: this may be way to much subjectivity, but I'd split the if check to something like this:
and I don't think line 702 (if ($string2->isType(T_ARRAY)) {) must be inside the if in 693 so I think this would be more readable and stil work as designed.
line 848: why $varr = $variable? $variable isn't modified somewhere so I think you could just use $variable instead of $varr.
line 949: instead of
I think you could just do
or even just
line 1228: I believe this is redundant:
Not all functions specify what they @return in the doc block. Variable naming is sometimes hard to follow, atleast for me.
I will surely use this module in my own projects! Thanks for your work :)
Comment #9
udaksh commentedHi Odegard,
Thanks a lot for the review.
I have fixed all the issues raised by you except the one on lines 145-147.
Yes you are correct I am making one big file which contains the source code of a complete module. I am making this file to prevent jumping from one file to another if a function is defined in one file and is called from some other files. Through this way we can have all the functions of a module in a single file and we can perform the scanning only in a single file. I am only combining the code of files with extension (.inc, .module or .php) .
Please let me know if there is any another way of doing the same and when this will result into an error.
Thank You,
Comment #10
r2integrated commentedThe git link you provide in your original post is the maintainer version, not the non-maintainer version. Please replace with
git clone --recursive --branch 7.x-1.x http://git.drupal.org/sandbox/udaksh/1611500.git security_testingAutomated review:
http://ventral.org/pareview/httpgitdrupalorgsandboxudaksh1611500git
Manual Review:
Wow, this is a rather complex module. I just scratched the surface, but I think I've found enough issues to be worked on. Let me preface this by saying that you shouldn't take the number of issues I have listed as an indication that there are serious issues with your code - on the contrary, your code is rather well written. It is simply a very large module and with more code comes more bugs more often than not. I think the module has great potential and I would encourage you to continue to hone its security detection capabilities.
return system_settings_form($form);is valid and doesn't constitute any security risk that I can detect.Comment #11
r2integrated commentedComment #11.0
r2integrated commentedAdded more application reviews
Comment #12
odegard commentedHi Udaksh, let me illustrate what I mean with an example:
my-module.module:
my-module.inc:
When you strip out, combine them and add a php-tag you end up with this:
Now closing files with ?> isn't what you should do, but then, it might happen and is easy to correct by stripping out ?>'s as well.
Did that make sense?
Comment #13
fotuzlab commentedDeleting my comment through edit. I misunderstood the above comment. Apologies!
Comment #14
udaksh commentedHi R2integrated ,
Thanks for the review. I have made the changes suggested by you. As per your point 3, I would like to tell how security testing actually works for checking Cross Site Scripting vulnerability. I have made security testing as a generalized module for scanning and anyone can configure it as he thinks.
I have divided all the function calls into 3 types
- Output function calls - The function calls that will display the value of its arguments on the screen. For ex - calls like drupal_set_message(), theme() etc.
-Secure function calls - The function call that will filter the value of its arguments .For ex - check_plain(), filter_xss() etc
-Normal function calls - All function calls that do not sanitize the value of its arguments but we knows that these function calls are also not harmful.
Security testing performs back-searching from the output function calls and searches to find from where the arguments of the output function call can get its value. While back-searching if we encounter any secure function call then we stop, because now we are sure that the value coming to the output function call is sanitized. If we encounter any Normal function call while back-searching then we simply ignore the function call and continue back-searching for the arguments present in the function call. If we encounter any other call while back-searching then we simply display a warning message to the user that we do not know anything about this function call,it might be vulnerable. You see a warning message about system_settings_form(), drupal_mail(), user_preferred_language(), token_replace() because security testing does not know anything about these function calls. This warning means that the return value this function call is going to the output function call and could be displayed as a message on the screen.
As there are many function calls in in php and Drupal and new function calls are constantly being adding, so I leave it to the user to configure these function calls. Now i have only added a very function calls in the database. If any user is sure that a function call which is giving a warning message is a normal function call(means it will do not cause any vulnerability) then he could simply add that function call in the normal_function_calls. So if I add system_settings_form() in the normal_function_call then it will not display the warning message next time for this call. Similar is the case with secure and output function calls.We can add more secure and output function calls.
Security Testing predicts all the areas where Cross Site Scripting could happen.
For your point 4 :
Sorry, I think i made a spelling mistake in readme.txt. The test is in the group Security Testing.
Comment #15
udaksh commentedThank You Odegard for the example,
I have tested Security Testing project with your example and yes it is resulting into an error.
I have fixed this issue by implementing the stripping out of "?>".
Thanks,
Comment #16
udaksh commentedComment #17
klausiReview of the 7.x-1.x branch:
This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. You have to get a review bonus to get a review from me.
manual review:
Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.
Comment #17.0
klausiChanged git clone command
Comment #17.1
udaksh commentedAdded more application reviews
Comment #18
udaksh commentedThank You Klausi for the review,
I have fixed all the issues. I am currently using Xampp 1.8.1 which has PHP version PHP 5.4.7 on ubuntu. I am getting correct results while using drush sec-test command.
Regards,
Udit Jaggi
Comment #19
klausimanual review:
Regarding the segmentation fault: please check if this works for you:
That results in a segmentation fault on my computer, also in the web interface.
So while I personally have some severe issues with the code I see no real application blockers, therefore I guess this is RTBC. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.
Comment #20
udaksh commentedSorry, Deleting my comment through edit.
Comment #21
udaksh commentedHi,
I will fix the issues raised and modify my code as soon as possible by adding more documentation, removing '@' and global variables, and applying fix to the other issues.
I think this project requires a bit of more work so I am changing the status to needs work and will get back to needs review after applying appropriate fixes to the issues raised.
Thanks,
Comment #21.0
udaksh commentedadded more reviews
Comment #22
udaksh commentedHi,
I have fixed all the issues raised. Added more documentation and removed all the global variables and @.
For 3 in #19:-
I am not using simpletest for Unit / Integration testing of security_testing module. I have used simpletest for testing of CSRF vulnerability in a drupal module. Security testing simpletest will get the name of the module to be tested from the module_name.txt file. Security_testing module first inserts random data into the simpletest database of a module so that links with %placeholder become active. Then it will go to each menu link defined in the hook_menu of a module and checks for CSRF vulnerability by analyzing database logs. If any INSERT/ DELETE / UPDATE query from the module runs while visiting a link then that module is vulnerable to CSRF. This checking is done in the security_testing_shutdown() function. I am also injecting XSS values into the database fields to check whether the injected values becomes sanitized or not while coming as an output message. I am storing the results of simpletest in a file simpletest_results.txt which is stored inside security_testing folder in the default drupal file directory. For simpletest security_testing to work the Drupal module needs to be present in the sites/all/modules directory. I have added some debug and assert statements. Please provide your review and suggest changes if any.
I have cloned the restws module and tried drush sec-test drush sec-test /path/to/restws but I am not getting the segmentation fault. I am getting this warning when i run drush sec-test with restws module :- htmlspecialchars() expects parameter 1 to be string, object given on line 1545 in /opt/lampp/htdocs/drupal/includes/bootstrap.inc (Warning). After this warning message everything runs good and i am getting the results. The restws is also running as expected in my Web Interface. I have attached the screenshots of testing restws.
Thanks,
Udaksh
Comment #23
klausiAh, I should have read the @file comment in the test file.
Review of the 7.x-1.x branch:
This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. You have to get a review bonus to get a review from me.
manual review:
Back to RTBC. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.
Comment #24
udaksh commentedThank you Klausi,
I have removed all backup files, .goutputstream-07DVOW and changed the variable name.
Thanks,
Udaksh
Comment #25
klausino objections for more than a week, so ...
Thanks for your contribution, udaksh!
I updated your account to let you promote this to a full project and also create new projects as either a sandbox or a "full" project.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and get involved!
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
Thanks to the dedicated reviewer(s) as well.
Comment #26
udaksh commentedThank you Klausi and everyone for all your valuable reviews and comments.
Comment #28
ndobromirov commentedIt looks like a nice module, but the command in the description:
git clone --recursive --branch 7.x-1.x http://git.drupal.org/sandbox/udaksh/1611500.git security_testing
Is giving me the following output in the terminal:
Cloning into 'security_testing'...
fatal: http://git.drupal.org/sandbox/udaksh/1611500.git/info/refs not found: did you run git update-server-info on the server?
Help in solving the issue will be appreciated.
Best regards,
Nikolay D.
Comment #29
ankitchauhan commented@ndobromirov - This isn't sandbox project now. you can try it as
git clone --recursive --branch 7.x-1.x http://git.drupal.org/project/securitytesting.gitComment #29.0
ankitchauhan commentedadded additional reviews