SEARCH
TOOLBOX
LANGUAGES
modified on 28 June 2010 at 17:11 ••• 1,535 views

O2 Script/Removing Spam pages from OWASP website (28 Jun 2010)

From

Jump to: navigation, search

Contents


On the 28th June 2010, Paolo Perego noticed that there were a number of spam pages deteted in the OWASP website. He alerted the owasp-leaders list and we started looking at this issue. Since cleaning up these pages was more than removing one page, lets use this problem as a case study, so that we see a number of O2 scripts in action.

This script uses the O2's Media Wiki API and MediaWiki Editor scripts

Taking a screenshot of an affected page

This first script will:

  • open a new instance of IE
  • open one of the afected pages
  • take a screenshot of the entire page
  • show the screenshot in a WinForms picture box, and
  • copy the screenshot into the clipboard
var ie2 = "http://www.owasp.org/index.php/How_to_convert_YouTube_to_iPhone_4_video".ie(0,0, 800,600);    
 
var screenshot = ie2.screenshot(); 
panel.clear();
panel.add_PictureBox().show(screenshot);  
panel.putBitmapOnClipboard(screenshot.bitmap());


Once the screenshot is in the clipboard we can use the O2 MediaWiki editor tool to copy it to a MediaWiki website (in this case the o2platform.com website). This is done by opening up the page to edit and (while the image is in the clipboard pressing Paste (i.e. Ctrl+V)

Looking at the resources used in this page

the following script will show the raw xml data that can be retrieved for any page using MediaWiki's API.php

panel.clear();
var codeViewer = panel.add_SourceCodeViewer();
var wikiApi = new OwaspWikiAPI();
var targetPage = "How_to_convert_YouTube_to_iPhone_4_video";
var xml = wikiApi.parsePage_Raw(targetPage).xmlFormat();
codeViewer.open(xml.saveWithExtension(".xml"));

Image:6_28_2010_4_33_26_PM_tmp3ED8.jpg

From that list we get the images used (which will also need to be deleted) and also a number of external links (to www.aneesoft.com)


Listing pages from a particular domain

A small variation of the previous script allows us to see all pages in the OWASP wiki that point to the www.aneesoft.com domain

panel.clear();
var codeViewer = panel.add_SourceCodeViewer();
var wikiApi = new OwaspWikiAPI();
var targetPage = "How_to_convert_YouTube_to_iPhone_4_video"; 
var xml =  wikiApi.exUrlUsage("www.aneesoft.com").xmlFormat();
codeViewer.open(xml.saveWithExtension(".xml"));

Image:6_28_2010_4_34_18_PM_tmp3EE2.jpg

Once we have that list we will want to extract the title attribute value

var wikiApi = new OwaspWikiAPI(false);
var xml =  wikiApi.exUrlUsage("www.aneesoft.com").xmlFormat();  
var xRoot = xml.xRoot();
var pages = xRoot.element("query").element("exturlusage").elements("eu").attributes("title").values();//("eu"); 
return pages;

Image:6_28_2010_4_42_44_PM_tmp3FF9.jpg

Finding the images used on all pages

Now that we have a list of pages we want to delete, we need to find out all unique images used by those pages

Here is a script that populates a treeview with the images that are used by all pages that contain a link to www.aneesoft.com

panel.clear();
var wikiApi = new OwaspWikiAPI(false); 
var treeView = panel.add_TreeView();
foreach(var page in wikiApi.exUrlUsage("www.aneesoft.com"))
{
	var node = treeView.add_Node(page); 
	foreach(var image in wikiApi.images(page))
		node.add_Node(image);
}

Putting it all together and deleting pages and images

This final script will:

  • login with an account with admin priviledges in the OWASP Wiki
  • get all pages that contain a link to www.aneesoft.com
  • foreach of those pages get the list of images used
  • create a unique list of images used
  • delete all pages and images discovered in the previous steps
var wikiApi = new OwaspWikiAPI(false);    
var credential = @"C:\O2\_USERDATA\O2TestUsers.xml".credentials()[4];
wikiApi.login(credential.username(), credential.password()); 
if (wikiApi.loggedIn()) 
	"user logged in".info();
 
var pagesToDelete = wikiApi.exUrlUsage("www.aneesoft.com");
var imagesToDelete = new List<String>(); 
 
foreach(var page in pagesToDelete)
	imagesToDelete.add_OnlyNewItems(wikiApi.images(page));	
return pagesToDelete;
wikiApi.deletePages(pagesToDelete);
wikiApi.deletePages(imagesToDelete);
 
return "done";
  • here is a sample of the logs created during the script execution:

Image:6_28_2010_5_47_57_PM_tmp4324.jpg

Image:6_28_2010_5_46_07_PM_tmp4323.jpg

  • and as a final source code example, here is how to show the recent changes in a TreeView
panel.clear();
panel.add_TreeView()
	 .add_Nodes(new OwaspWikiAPI(false).recentChanges());
return "ok";

Image:6_28_2010_5_51_08_PM_tmp4368.jpg

MediaWiki Appliance - Powered by TurnKey Linux