Skip to content

Development Guide

Saeed Dehqan edited this page Apr 8, 2020 · 2 revisions

Make a module

First: Insert your module into the corresponding directory in the module directory. i.e , if your module is a scanning module, you can create a new directory in the "module" directory called "scan" and place your module to the scan directory. Modules added to "scan" directory are loaded into the framework at runtime and listed under a category matching the directory's name. You can easily run your module by name in framework.

tool mode:

[maryam][default] > godork

module mode:

[maryam][default] > use osint/godork

Module Structure

# BaseModule class is require
from core.module import BaseModule

# The Module class name does not change
class Module(BaseModule):
    # modules are defined and configured by the "meta" class variable
    # "meta" is a dictionary that contains information about the module, ranging from basic information, 
    # below is an example "meta" declaration that contains all of the possible definitions
	meta = {
		# Complete Module Name
		"name": "Google Dork Search",
		"author": "Saeeddqn",
		"version": "0.2",
		"description": "Search your dork in the google and get result",
		"comments": (
			"Notes",
			"Notes"
		),
		# Sources that you use in your module
		"sources": ("google",),
		"options": (
			# ("<OPTION-NAME", "<VALUE>", "<DESCRIPTION>", "<SHORTOPTS>", "<ACTION>")
			("dork", None, True, "Google dork string", "-d", "store"),
			("limit", 2, False, "Google search limit", "-l", "store"),
			("count", 50, False, "Link count in page(min=10, max=100)", "-c", "store"),
			# The output option is require and it is used to store the module output.
			("output", False, False, "Save output to workspace", "--output", "store_false"),
		),
        "examples": ("godork -d <DORK> -l 15 --output",)
	}
	# the core of your module override on the module_run
	def module_run(self):
		# Use the option name to access option values.
		dork = self.options["dork"]
		limit = self.options["limit"]
		count = self.options["count"]
		# This is how you can access ready classes: self.<class_name>(args).<methods>
		run = self.google(dork, limit, count)
		run.run_crawl()
		links = run.links

		if links == []:
			self.output("Without result")
		else:
			for link in links:
				self.output("\t%s" % link, "g")
		# self.save_gather({<DATA>}, "<Module-Name>", "<QUERY|DORK|HOSTNAME>", <OUTPUT-FLAG(True,False)>)
		self.save_gather({"links" : links}, "osint/godork", dork, output=self.options["output"])

Make a util class

Utils classes use in modules. Usually classes are added to the util directory that are widely used and indirectly used by the user and used directly by the developers.

An example class

class main:

	def __init__(self, framework, q, limit):
		self.framework = framework
		self.q = self.framework.urlib(q).quote
		self.limit = 20 if limit > 20 else limit
		self._pages = ""
		self.ask = "ask.com"

	def run_crawl(self):
		urls = ["https://%s/web?q=%s&page=%d" % (self.ask, self.q, i) for i in range(1, self.limit)]
		max_attempt = len(urls)
		for url in urls:
			try:
				req = self.framework.request(url=url)
			except Exception as e:
				self.framework.error(str(e.args))
				max_attempt -= 1
				if max_attempt == 0:
					self.framework.error("ask is missed!")
					break
			else:
				page = req.text
				if ">Next</li>" not in page:
					self._pages += page
					break
				self._pages += page

	@property
	def pages(self):
		return self._pages

	@property
	def dns(self):
		return self.framework.page_parse(self._pages).get_dns(self.q)

	@property
	def emails(self):
		return self.framework.page_parse(self._pages).get_emails(self.q)

	@property
	def docs(self):
		return self.framework.page_parse(self._pages).get_docs(self.q)

After that, you can create an interface for this class to "module.py":

	def ask(self, q, limit=5):
		search = ask.main(self, q, limit)
		return search

In the next you can use ask class in modules:

	def module_run(self):
		run = self.ask("microsoft.com", 5)
		run.run_crawl
		emails = run.emails
		for i in emails:
			self.output(i)

Ready methods

  • for send a request and get response
	# All of params
	req = self.request(url=url, agent=agent, timeout=timeout, headers={}, rand_agent=True, 
		cookie=cookie, auth={}, redirect=False, method="POST", content='', payload={}, proxy=proxy)
	# A simple request
	req = self.request(url)
	# Response(Response is a requests object)
	req.headers # headers
	req.status_code # Status request code
	req.text # read
	req.json() # json data
  • print errors and exceptions
	self.error("this is an error")
	# output: [!] This is an error.
  • print normal output
	self.output("this is a normal output", color="N") # color is optional.default="N"
	# colors = {'N' : 'native', 'R' : 'red', 'B' : 'blue', 'G' : 'green', 'O' : 'orange', 'P' : 'purple', 'C' : 'cyan'}
	# output: [*] this is a normal output
	
  • Formats and presents important output.
	self.alert("this is an alert")
	# output: [*] this is a normal output
	# color: green
  • Formats and presents output if in debug mode (very verbose)
	self.debug("msg")
	# output: [*] msg
	# color: blue
  • Formats and presents output if in verbose mode.
	self.verbose('This is verbose output')
	# output: [*] This is verbose output
	# color: blue
  • Formats and presents styled header text
	self.heading("PHONE", 0)
	# output:

	# -----
	# PHONE
	# -----
	self.heading("PHONE")
	# output:

	# PHONE
	# -----
  • Format and display a heading.
    • level is the style of heading. Currently there are only two style options: 0 and 1.
  • Build, display, and store an ASCII table of given data.
    • tdata is the table data as a two dimensional list (list of lists), with each list representing a row of data. Each list must be the same length.
    • header (optional) is a list containing the header values. By default, tables are displayed without a header row.
    • title (optional) is the title of the table. By default, tables are displayed without a title.
	self.table(table_data, header=['host', 'ip_address'], title='Hosts')
	# output: 
	"""
	  +-------------------------------------+
	  |                Hosts                |
	  +-------------------------------------+
	  |        host        |   ip_address   |
	  +-------------------------------------+
	  | www.apache.org     | 192.87.106.229 |
	  | www.google.com     | 74.125.225.176 |
	  | www.twitter.com    | 199.59.148.10  |
	  | www.whitehouse.gov | 157.238.74.67  |
	  +-------------------------------------+
	"""
  • json output
	self.exporter(filename, value, format)
	# Format can be json,txt,xml,csv

Note: If you have any question please contact me

You can’t perform that action at this time.