@@ -97,27 +97,56 @@ export const PARAM_DEFINITIONS: ParamDefinition[] = [
9797 { key : 'threads' , name : 'threads' , cliName : '--threads' , description : '并发线程数' , category : 'optimization' , type : 'integer' , defaultValue : 1 , min : 1 , max : 10 } ,
9898
9999 // Enumeration 枚举
100+ { key : 'getAll' , name : 'all' , cliName : '--all' , description : '枚举所有信息' , category : 'enumeration' , type : 'boolean' } ,
100101 { key : 'getBanner' , name : 'banner' , cliName : '--banner' , description : '获取DBMS Banner' , category : 'enumeration' , type : 'boolean' } ,
101102 { key : 'getCurrentUser' , name : 'current-user' , cliName : '--current-user' , description : '获取当前用户' , category : 'enumeration' , type : 'boolean' } ,
102103 { key : 'getCurrentDb' , name : 'current-db' , cliName : '--current-db' , description : '获取当前数据库' , category : 'enumeration' , type : 'boolean' } ,
104+ { key : 'getHostname' , name : 'hostname' , cliName : '--hostname' , description : '获取主机名' , category : 'enumeration' , type : 'boolean' } ,
103105 { key : 'isDba' , name : 'is-dba' , cliName : '--is-dba' , description : '检测是否为DBA' , category : 'enumeration' , type : 'boolean' } ,
104106 { key : 'getUsers' , name : 'users' , cliName : '--users' , description : '枚举用户' , category : 'enumeration' , type : 'boolean' } ,
107+ { key : 'getPasswordHashes' , name : 'passwords' , cliName : '--passwords' , description : '获取密码哈希' , category : 'enumeration' , type : 'boolean' } ,
108+ { key : 'getPrivileges' , name : 'privileges' , cliName : '--privileges' , description : '获取权限' , category : 'enumeration' , type : 'boolean' } ,
109+ { key : 'getRoles' , name : 'roles' , cliName : '--roles' , description : '获取角色' , category : 'enumeration' , type : 'boolean' } ,
105110 { key : 'getDbs' , name : 'dbs' , cliName : '--dbs' , description : '枚举数据库' , category : 'enumeration' , type : 'boolean' } ,
106111 { key : 'getTables' , name : 'tables' , cliName : '--tables' , description : '枚举表' , category : 'enumeration' , type : 'boolean' } ,
107112 { key : 'getColumns' , name : 'columns' , cliName : '--columns' , description : '枚举列' , category : 'enumeration' , type : 'boolean' } ,
113+ { key : 'getSchema' , name : 'schema' , cliName : '--schema' , description : '获取Schema' , category : 'enumeration' , type : 'boolean' } ,
114+ { key : 'getCount' , name : 'count' , cliName : '--count' , description : '获取记录数' , category : 'enumeration' , type : 'boolean' } ,
115+ { key : 'getComments' , name : 'comments' , cliName : '--comments' , description : '获取注释' , category : 'enumeration' , type : 'boolean' } ,
116+ { key : 'getStatements' , name : 'statements' , cliName : '--statements' , description : '获取SQL语句' , category : 'enumeration' , type : 'boolean' } ,
108117 { key : 'dumpTable' , name : 'dump' , cliName : '--dump' , description : '导出数据' , category : 'enumeration' , type : 'boolean' } ,
109118 { key : 'dumpAll' , name : 'dump-all' , cliName : '--dump-all' , description : '导出所有数据' , category : 'enumeration' , type : 'boolean' } ,
119+ { key : 'dumpWhere' , name : 'where' , cliName : '--where' , description : 'dump条件' , category : 'enumeration' , type : 'string' } ,
120+ { key : 'limitStart' , name : 'start' , cliName : '--start' , description : '起始行' , category : 'enumeration' , type : 'integer' , min : 0 } ,
121+ { key : 'limitStop' , name : 'stop' , cliName : '--stop' , description : '结束行' , category : 'enumeration' , type : 'integer' , min : 0 } ,
122+ { key : 'firstChar' , name : 'first' , cliName : '--first' , description : '起始字符位' , category : 'enumeration' , type : 'integer' , min : 0 } ,
123+ { key : 'lastChar' , name : 'last' , cliName : '--last' , description : '结束字符位' , category : 'enumeration' , type : 'integer' , min : 0 } ,
110124 { key : 'db' , name : 'database' , cliName : '-D' , description : '指定数据库' , category : 'enumeration' , type : 'string' } ,
111125 { key : 'tbl' , name : 'table' , cliName : '-T' , description : '指定表' , category : 'enumeration' , type : 'string' } ,
112126 { key : 'col' , name : 'column' , cliName : '-C' , description : '指定列' , category : 'enumeration' , type : 'string' } ,
113-
127+ { key : 'extensiveFp' , name : 'fingerprint' , cliName : '--fingerprint' , description : '深度指纹识别' , category : 'enumeration' , type : 'boolean' } ,
128+
129+ // Techniques 扩展
130+ { key : 'uCols' , name : 'union-cols' , cliName : '--union-cols' , description : 'UNION列数范围' , category : 'techniques' , type : 'string' } ,
131+ { key : 'uChar' , name : 'union-char' , cliName : '--union-char' , description : 'UNION填充字符' , category : 'techniques' , type : 'string' } ,
132+ { key : 'uFrom' , name : 'union-from' , cliName : '--union-from' , description : 'UNION FROM表' , category : 'techniques' , type : 'string' } ,
133+ { key : 'uValues' , name : 'union-values' , cliName : '--union-values' , description : 'UNION填充值' , category : 'techniques' , type : 'string' } ,
134+
114135 // General 通用
136+ { key : 'requestFile' , name : 'request file' , cliName : '-r' , description : 'HTTP请求文件' , category : 'general' , type : 'string' } ,
137+ { key : 'sessionFile' , name : 'session file' , cliName : '-s' , description : '会话文件' , category : 'general' , type : 'string' } ,
138+ { key : 'trafficFile' , name : 'traffic file' , cliName : '-t' , description : '流量日志文件' , category : 'general' , type : 'string' } ,
115139 { key : 'batch' , name : 'batch' , cliName : '--batch' , description : '批处理模式(不提问)' , category : 'general' , type : 'boolean' , defaultValue : true } ,
116140 { key : 'forms' , name : 'forms' , cliName : '--forms' , description : '解析并测试表单' , category : 'general' , type : 'boolean' } ,
117141 { key : 'crawlDepth' , name : 'crawl' , cliName : '--crawl' , description : '爬取深度' , category : 'general' , type : 'integer' , min : 0 , max : 10 } ,
118142 { key : 'flushSession' , name : 'flush-session' , cliName : '--flush-session' , description : '刷新会话文件' , category : 'general' , type : 'boolean' } ,
119143 { key : 'freshQueries' , name : 'fresh-queries' , cliName : '--fresh-queries' , description : '忽略会话缓存' , category : 'general' , type : 'boolean' } ,
120- { key : 'verbose' , name : 'verbose' , cliName : '-v' , description : '详细级别 (0-6)' , category : 'general' , type : 'integer' , defaultValue : 1 , min : 0 , max : 6 }
144+ { key : 'verbose' , name : 'verbose' , cliName : '-v' , description : '详细级别 (0-6)' , category : 'general' , type : 'integer' , defaultValue : 1 , min : 0 , max : 6 } ,
145+ { key : 'answers' , name : 'answers' , cliName : '--answers' , description : '预定义答案' , category : 'general' , type : 'string' } ,
146+ { key : 'rParam' , name : 'randomize' , cliName : '--randomize' , description : '随机化参数值' , category : 'general' , type : 'string' } ,
147+ { key : 'evalCode' , name : 'eval' , cliName : '--eval' , description : '执行Python代码' , category : 'general' , type : 'string' } ,
148+ { key : 'shLib' , name : 'shared-lib' , cliName : '--shared-lib' , description : '共享库路径' , category : 'general' , type : 'string' } ,
149+ { key : 'regVal' , name : 'reg-value' , cliName : '--reg-value' , description : '注册表值' , category : 'general' , type : 'string' } ,
121150]
122151
123152// 根据key获取参数定义
@@ -129,3 +158,58 @@ export function getParamDefinition(key: string): ParamDefinition | undefined {
129158export function getParamByCliName ( cliName : string ) : ParamDefinition | undefined {
130159 return PARAM_DEFINITIONS . find ( p => p . cliName === cliName )
131160}
161+
162+ // 驼峰转连字符(后备方案,用于映射表中未定义的参数)
163+ export function camelToKebab ( str : string ) : string {
164+ return str . replace ( / ( [ A - Z ] ) / g, '-$1' ) . toLowerCase ( ) . replace ( / ^ - / , '' )
165+ }
166+
167+ // 创建 key→cliName 映射表(缓存用,避免每次遍历数组)
168+ let _paramKeyToCliNameMap : Map < string , string > | null = null
169+ export function getParamKeyToCliNameMap ( ) : Map < string , string > {
170+ if ( ! _paramKeyToCliNameMap ) {
171+ _paramKeyToCliNameMap = new Map < string , string > ( )
172+ for ( const param of PARAM_DEFINITIONS ) {
173+ _paramKeyToCliNameMap . set ( param . key , param . cliName )
174+ }
175+ }
176+ return _paramKeyToCliNameMap
177+ }
178+
179+ // 转换单个参数为命令行格式
180+ export function convertOptionToCliArg ( key : string , value : any ) : string | null {
181+ if ( value === false || value === null || value === undefined || value === '' ) {
182+ return null
183+ }
184+
185+ const map = getParamKeyToCliNameMap ( )
186+ // 优先使用映射表中的 cliName
187+ let cliName = map . get ( key )
188+ if ( ! cliName ) {
189+ // 后备: 驼峰转连字符
190+ cliName = '--' + camelToKebab ( key )
191+ }
192+
193+ if ( value === true ) {
194+ return cliName
195+ }
196+
197+ const formatted = formatCliValue ( value )
198+ // 短选项(如 -v, -D 等)用空格分隔值
199+ if ( / ^ - [ a - z A - Z ] $ / . test ( cliName ) ) {
200+ return `${ cliName } ${ formatted } `
201+ }
202+ return `${ cliName } =${ formatted } `
203+ }
204+
205+ // 格式化命令行参数值
206+ function formatCliValue ( value : any ) : string {
207+ if ( Array . isArray ( value ) ) {
208+ return value . join ( ',' )
209+ }
210+ const str = String ( value )
211+ if ( / [ \s , ; | & " ' ] / . test ( str ) ) {
212+ return `"${ str . replace ( / " / g, '\\"' ) } "`
213+ }
214+ return str
215+ }
0 commit comments