Library mysql
Simple MySQL Library supporting a very limited subset of operations.
http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol
Author:
| "Patrik Karlsson <patrik@cqure.net>" |
Copyright© Same as Nmap--See http://nmap.org/book/man-legal.html
Source: http://nmap.org/svn/nselib/mysql.lua
Functions
| decodeDataPackets (data, count) |
Decodes the row data |
| decodeField (data, pos) |
Decodes a single column field |
| decodeFieldPackets (data, count) |
Decodes as field packet and returns a table of field tables |
| decodeQueryResponse (socket) |
Decodes the result set header packet into it's sub components |
| formatResultset (rs, options) |
Formats the resultset returned from |
| loginRequest (socket, params, username, password, salt) |
Attempts to Login to the remote mysql server |
| receiveGreeting (socket) |
Recieves the server greeting upon intial connection |
| sqlQuery (socket, query) |
Sends the query to the MySQL server and then attempts to decode the response |
Functions
- decodeDataPackets (data, count)
-
Decodes the row data
ref: http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#Row_Data_Packet
Parameters
- data: string containing the row data packet
- count: number containing the number of fields to decode
Return values:
- status true on success, false on failure
- rows table containing row tables
- decodeField (data, pos)
-
Decodes a single column field
http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#Field_Packet
Parameters
- data: string containing field packets
- pos: number containing position from which to start decoding the position should point to the data in this buffer (ie. after the header)
Return values:
- pos number containing the position after the field was decoded
- field table containing
catalog,database,table,origt_table,name,orig_name,lengthandtype
- decodeFieldPackets (data, count)
-
Decodes as field packet and returns a table of field tables
ref: http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#Field_Packet
Parameters
- data: string containing field packets
- count: number containing the amount of fields to decode
Return values:
- status boolean (true on success, false on failure)
- fields table containing field tables as returned by
decodeFieldor string containing error message if status is false
- decodeQueryResponse (socket)
-
Decodes the result set header packet into it's sub components
ref: http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol#Result_Set_Header_Packet
Parameters
- socket: socket already connected to MySQL server
Return value:
table containing the followingheader,fieldsanddata - formatResultset (rs, options)
-
Formats the resultset returned from
sqlQueryParameters
-
rs:
table as returned from
sqlQuery -
options:
table containing additional options, currently:
-
noheaders- does not include column names in result
Return value:
string containing the formated resultset table -
rs:
table as returned from
- loginRequest (socket, params, username, password, salt)
-
Attempts to Login to the remote mysql server
Parameters
- socket: already connected to the remote server
-
params:
table with additional options to the loginrequest
current supported fields are
charsetandauthversionauthversion is either "pre41" or "post41" (default is post41) currently only post41 authentication is supported - username: string containing the username of the user that is authenticating
- password: string containing the users password or nil if empty
-
salt:
string containing the servers salt as recieved from
receiveGreeting
Return values:
- status boolean
- response table or error message on failure
- receiveGreeting (socket)
-
Recieves the server greeting upon intial connection
Parameters
- socket: already connected to the remote server
Return values:
- status true on success, false on failure
- response table with the following fields
proto,version,threadid,salt,capabilities,charsetandstatusor error message on failure (status == false)
- sqlQuery (socket, query)
-
Sends the query to the MySQL server and then attempts to decode the response
Parameters
- socket: socket already connected to mysql
- query: string containing the sql query
Return values:
- status true on success, false on failure
- rows table containing row tabels as decoded by
decodeDataPackets


