ITADN

Update inference.py

#5953Pull Requestkn1g78 创建于 2025-08-31
K
kn1g78commented
# SQLMap Dictionary Similarity Feature ## Feature Description This feature adds intelligent dictionary matching capability to sqlmap's blind injection. When the partially inferred string during blind injection has high similarity with common database/table names in the dictionary, it will directly test the complete dictionary item, greatly saving blind injection time. ## How It Works 1. **Similarity Check**: During blind injection, when at least 3 characters are inferred, it checks similarity with dictionary items 2. **Threshold Judgment**: If similarity exceeds 0.8 (configurable), it attempts to test the complete dictionary item 3. **Fast Matching**: If the test succeeds, it directly returns the complete result, skipping remaining character inference ## Usage ### 1. Dictionary Files The feature automatically selects the appropriate dictionary based on the query type: - **Tables/Databases**: Uses `data/txt/common-tables.txt` for table and database name inference - **Columns**: Uses `data/txt/common-columns.txt` for column name inference These files already contain common database, table, and column names. You can add more entries to these files if needed. ### 2. Normal sqlmap Usage The feature is automatically enabled without additional parameters. When blind injection encounters content similar to dictionary items, it will display information like: ``` [INFO] checking tables dictionary similarity for 'info' (similarity: 0.90) [INFO] Tables dictionary match successful: 'information_schema' [INFO] checking columns dictionary similarity for 'user' (similarity: 0.85) [INFO] Columns dictionary match successful: 'username' ``` ## Configuration Options ### Similarity Threshold You can modify the similarity threshold in `lib/techniques/blind/inference.py`: ```python # Similarity threshold for dictionary matching SIMILARITY_THRESHOLD = 0.8 # Can be adjusted between 0.7-0.9 ``` ### Minimum Character Count By default, similarity check is only performed when at least 3 characters are inferred. You can modify this in the code: ```python if len(partialValue) >= 3: # Can be adjusted between 2-5 ``` ## Advantages 1. **Significant Time Savings**: For common database/table names, can save over 90% of blind injection time 2. **Intelligent Matching**: Uses sequence matching algorithm to handle partial and similar matches 3. **Prefix Priority**: Gives higher weight to prefix matches, improving accuracy 4. **Backward Compatibility**: Does not affect existing blind injection functionality, only adds optimization ## Example Scenarios ### Scenario 1: Inferring Database Name - Blind injection inference: `info` -> `information_schema` - Time saved: Reduced from 15 character inferences to 4 character inferences ### Scenario 2: Inferring Table Name - Blind injection inference: `user` -> `users` - Time saved: Reduced from 5 character inferences to 4 character inferences ### Scenario 3: Inferring Admin Table - Blind injection inference: `adm` -> `admin` - Time saved: Reduced from 5 character inferences to 3 character inferences ### Scenario 4: Inferring Column Names - Blind injection inference: `user` -> `username` - Time saved: Reduced from 8 character inferences to 4 character inferences ## Notes 1. **Dictionary Quality**: The quality of the dictionary file directly affects matching effectiveness 2. **False Matches**: If the dictionary contains irrelevant items, it may cause false matches 3. **Performance Impact**: Similarity checking brings minimal performance overhead, but the time saved is worth it ## Troubleshooting ### Dictionary File Not Found Ensure `data/txt/common-tables.txt` and `data/txt/common-columns.txt` files exist and are readable ### Similarity Check Not Working Check if there are "checking dictionary similarity" messages in the logs ### Match Failure Try lowering the similarity threshold or adding more relevant items to the appropriate dictionary file ## Technical Implementation - **Similarity Algorithm**: Uses Python's difflib.SequenceMatcher - **Integration Location**: lib/techniques/blind/inference.py - **Supported Modes**: Single-threaded and multi-threaded blind injection - **Caching Mechanism**: Dictionary content is cached for performance
合并状态:未合并 关闭于 2025-09-01 4 条评论