~ubuntu-branches/ubuntu/vivid/sqlmap/vivid

« back to all changes in this revision

Viewing changes to lib/controller/action.py

  • Committer: Bazaar Package Importer
  • Author(s): Bernardo Damele A. G.
  • Date: 2009-02-03 23:30:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090203233000-8gpnwfbih0wnqtv5
Tags: upstream-0.6.4
ImportĀ upstreamĀ versionĀ 0.6.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
"""
 
4
$Id: action.py 327 2009-01-12 21:35:38Z inquisb $
 
5
 
 
6
This file is part of the sqlmap project, http://sqlmap.sourceforge.net.
 
7
 
 
8
Copyright (c) 2006-2009 Bernardo Damele A. G. <bernardo.damele@gmail.com>
 
9
                        and Daniele Bellucci <daniele.bellucci@gmail.com>
 
10
 
 
11
sqlmap is free software; you can redistribute it and/or modify it under
 
12
the terms of the GNU General Public License as published by the Free
 
13
Software Foundation version 2 of the License.
 
14
 
 
15
sqlmap is distributed in the hope that it will be useful, but WITHOUT ANY
 
16
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
17
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
18
details.
 
19
 
 
20
You should have received a copy of the GNU General Public License along
 
21
with sqlmap; if not, write to the Free Software Foundation, Inc., 51
 
22
Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
23
"""
 
24
 
 
25
 
 
26
 
 
27
from lib.controller.handler import setHandler
 
28
from lib.core.common import getHtmlErrorFp
 
29
from lib.core.data import conf
 
30
from lib.core.data import kb
 
31
from lib.core.dump import dumper
 
32
from lib.core.exception import sqlmapUnsupportedDBMSException
 
33
from lib.core.settings import SUPPORTED_DBMS
 
34
from lib.techniques.blind.timebased import timeTest
 
35
from lib.techniques.inband.union.test import unionTest
 
36
from lib.techniques.outband.stacked import stackedTest
 
37
 
 
38
 
 
39
def action():
 
40
    """
 
41
    This function exploit the SQL injection on the affected
 
42
    url parameter and extract requested data from the
 
43
    back-end database management system or operating system
 
44
    if possible
 
45
    """
 
46
 
 
47
    # First of all we have to identify the back-end database management
 
48
    # system to be able to go ahead with the injection
 
49
    conf.dbmsHandler = setHandler()
 
50
 
 
51
    if not conf.dbmsHandler:
 
52
        htmlParsed = getHtmlErrorFp()
 
53
 
 
54
        errMsg  = "sqlmap was not able to fingerprint the "
 
55
        errMsg += "back-end database management system"
 
56
 
 
57
        if htmlParsed:
 
58
            errMsg += ", but from the HTML error page it was "
 
59
            errMsg += "possible to determinate that the "
 
60
            errMsg += "back-end DBMS is %s" % htmlParsed
 
61
 
 
62
        if htmlParsed and htmlParsed.lower() in SUPPORTED_DBMS:
 
63
            errMsg += ". Do not specify the back-end DBMS manually, "
 
64
            errMsg += "sqlmap will fingerprint the DBMS for you"
 
65
        else:
 
66
            errMsg += ". Support for this DBMS will be implemented if "
 
67
            errMsg += "you ask, just drop us an email"
 
68
 
 
69
        raise sqlmapUnsupportedDBMSException, errMsg
 
70
 
 
71
    print "%s\n" % conf.dbmsHandler.getFingerprint()
 
72
 
 
73
    # Techniques options
 
74
    if conf.stackedTest:
 
75
        dumper.string("stacked queries support", stackedTest())
 
76
 
 
77
    if conf.timeTest:
 
78
        dumper.string("time based blind sql injection payload", timeTest())
 
79
 
 
80
    if conf.unionTest:
 
81
        dumper.string("valid union", unionTest())
 
82
 
 
83
    # Enumeration options
 
84
    if conf.getBanner:
 
85
        dumper.string("banner", conf.dbmsHandler.getBanner())
 
86
 
 
87
    if conf.getCurrentUser:
 
88
        dumper.string("current user", conf.dbmsHandler.getCurrentUser())
 
89
 
 
90
    if conf.getCurrentDb:
 
91
        dumper.string("current database", conf.dbmsHandler.getCurrentDb())
 
92
 
 
93
    if conf.isDba:
 
94
        dumper.string("current user is DBA", conf.dbmsHandler.isDba())
 
95
 
 
96
    if conf.getUsers:
 
97
        dumper.lister("database management system users", conf.dbmsHandler.getUsers())
 
98
 
 
99
    if conf.getPasswordHashes:
 
100
        dumper.userSettings("database management system users password hashes",
 
101
                            conf.dbmsHandler.getPasswordHashes(), "password hash")
 
102
 
 
103
    if conf.getPrivileges:
 
104
        dumper.userSettings("database management system users privileges",
 
105
                            conf.dbmsHandler.getPrivileges(), "privilege")
 
106
 
 
107
    if conf.getDbs:
 
108
        dumper.lister("available databases", conf.dbmsHandler.getDbs())
 
109
 
 
110
    if conf.getTables:
 
111
        dumper.dbTables(conf.dbmsHandler.getTables())
 
112
 
 
113
    if conf.getColumns:
 
114
        dumper.dbTableColumns(conf.dbmsHandler.getColumns())
 
115
 
 
116
    if conf.dumpTable:
 
117
        dumper.dbTableValues(conf.dbmsHandler.dumpTable())
 
118
 
 
119
    if conf.dumpAll:
 
120
        conf.dbmsHandler.dumpAll()
 
121
 
 
122
    if conf.query:
 
123
        dumper.string(conf.query, conf.dbmsHandler.sqlQuery(conf.query))
 
124
 
 
125
    if conf.sqlShell:
 
126
        conf.dbmsHandler.sqlShell()
 
127
 
 
128
    # File system options
 
129
    if conf.rFile:
 
130
        dumper.string(conf.rFile, conf.dbmsHandler.readFile(conf.rFile))
 
131
 
 
132
    if conf.wFile:
 
133
        dumper.string(conf.wFile, conf.dbmsHandler.writeFile(conf.wFile))
 
134
 
 
135
    # Takeover options
 
136
    if conf.osShell:
 
137
        conf.dbmsHandler.osShell()