├── .gitignore ├── LICENSE ├── README.md ├── commands ├── __init__.py ├── add.py ├── clear.py ├── credits.py ├── delete.py ├── export.py ├── help.py ├── load.py ├── quit.py ├── run.py ├── search.py ├── select.py ├── set.py ├── show.py └── use.py ├── images ├── module.png └── preview.png ├── modules ├── crtsh.py ├── dbs.py ├── hackertarget.py ├── ipinfo.py ├── phpmyadmin.py ├── resolve.py └── urlscan.py ├── requirements.txt └── smog ├── __init__.py ├── __main__.py ├── api ├── crypto.py ├── dns.py └── http.py ├── banner.py ├── common ├── command.py ├── module.py └── type.py ├── database ├── __init__.py ├── database.py └── types │ ├── __init__.py │ ├── credentials.py │ ├── databaseserver.py │ ├── domain.py │ ├── email.py │ ├── ip_address.py │ ├── phone.py │ ├── port.py │ ├── social.py │ ├── subdomain.py │ └── url.py ├── logger.py ├── shell.py └── utils ├── arguments.py └── shell.py /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .DS_Store 3 | *.smog 4 | .idea 5 | a.sh 6 | modules/private_*.py 7 | 8 | # Byte-compiled / optimized / DLL files 9 | __pycache__/ 10 | *.py[cod] 11 | *$py.class 12 | 13 | # C extensions 14 | *.so 15 | 16 | # Distribution / packaging 17 | .Python 18 | build/ 19 | develop-eggs/ 20 | dist/ 21 | downloads/ 22 | eggs/ 23 | .eggs/ 24 | lib/ 25 | lib64/ 26 | parts/ 27 | sdist/ 28 | var/ 29 | wheels/ 30 | pip-wheel-metadata/ 31 | share/python-wheels/ 32 | *.egg-info/ 33 | .installed.cfg 34 | *.egg 35 | MANIFEST 36 | 37 | # PyInstaller 38 | # Usually these files are written by a python script from a template 39 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 40 | *.manifest 41 | *.spec 42 | 43 | # Installer logs 44 | pip-log.txt 45 | pip-delete-this-directory.txt 46 | 47 | # Unit test / coverage reports 48 | htmlcov/ 49 | .tox/ 50 | .nox/ 51 | .coverage 52 | .coverage.* 53 | .cache 54 | nosetests.xml 55 | coverage.xml 56 | *.cover 57 | *.py,cover 58 | .hypothesis/ 59 | .pytest_cache/ 60 | 61 | # Translations 62 | *.mo 63 | *.pot 64 | 65 | # Django stuff: 66 | *.log 67 | local_settings.py 68 | db.sqlite3 69 | db.sqlite3-journal 70 | 71 | # Flask stuff: 72 | instance/ 73 | .webassets-cache 74 | 75 | # Scrapy stuff: 76 | .scrapy 77 | 78 | # Sphinx documentation 79 | docs/_build/ 80 | 81 | # PyBuilder 82 | target/ 83 | 84 | # Jupyter Notebook 85 | .ipynb_checkpoints 86 | 87 | # IPython 88 | profile_default/ 89 | ipython_config.py 90 | 91 | # pyenv 92 | .python-version 93 | 94 | # pipenv 95 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 96 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 97 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 98 | # install all needed dependencies. 99 | #Pipfile.lock 100 | 101 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 102 | __pypackages__/ 103 | 104 | # Celery stuff 105 | celerybeat-schedule 106 | celerybeat.pid 107 | 108 | # SageMath parsed files 109 | *.sage.py 110 | 111 | # Environments 112 | .env 113 | .venv 114 | env/ 115 | venv/ 116 | ENV/ 117 | env.bak/ 118 | venv.bak/ 119 | 120 | # Spyder project settings 121 | .spyderproject 122 | .spyproject 123 | 124 | # Rope project settings 125 | .ropeproject 126 | 127 | # mkdocs documentation 128 | /site 129 | 130 | # mypy 131 | .mypy_cache/ 132 | .dmypy.json 133 | dmypy.json 134 | 135 | # Pyre type checker 136 | .pyre/ 137 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ``` 2 | . . 3 | .+'|=|`+. 4 | | | `+.| 5 | | | . 6 | `+.|=|`+. 7 | . | | Smog Framework 8 | |`+. | | version 1.2.0 9 | `+.|=|.+' 10 | 11 | ``` 12 | 13 | ## A semi-automatic osint/recon framework. 14 | 15 | ![](images/preview.png) 16 | 17 | ## Getting started: 18 | 19 | ### Requirements 20 | 21 | * git 22 | * Python >= 3.8 23 | 24 | ### Installation 25 | 26 | * `git clone https://github.com/traumatism/Smog/` 27 | 28 | * `cd Smog` 29 | 30 | * `pip3 install -r requirements.txt` 31 | 32 | * `python3 -m smog` 33 | 34 | * One line: `git clone https://github.com/traumatism/Smog/ && cd Smog && pip3 install -r requirements.txt && python3 -m smog` 35 | 36 | ### Usage 37 | 38 | Add a domain for example 39 | 40 | * `add domain domain.com` 41 | 42 | Scan for subdomains with differents modules 43 | 44 | * `use crtsh` 45 | 46 | * `run` 47 | 48 | * `use hackertarget` 49 | 50 | * `run` 51 | 52 | ... 53 | 54 | Now lets use the data we gathered to resolve the subdomains to IP addresses 55 | 56 | * `use resolve` 57 | 58 | * `run` 59 | 60 | Then we can use another module to gather IP addresses informations 61 | 62 | * `use ipinfo` 63 | 64 | * `run` 65 | 66 | Then we can look up for websites 67 | 68 | * `use urlscan` 69 | 70 | * `run` 71 | 72 | The process is quasi-infinite. You can add more modules to get more informations and add modules that uses these informations (that why its "semi-automatic", the actions order is decided by the human) 73 | 74 | ## Module example 75 | 76 | ![](images/module.png) 77 | 78 | ## TODO: 79 | 80 | ### Modules 81 | 82 | * Endpoints scanning 83 | * Vulnerability scanning 84 | 85 | ### Features 86 | 87 | * Key system 88 | * Automatic modules/commands loading 89 | -------------------------------------------------------------------------------- /commands/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Traumatism/Smog/397658a4743c3ed5ff2d0d837feef1e55d9a556f/commands/__init__.py -------------------------------------------------------------------------------- /commands/add.py: -------------------------------------------------------------------------------- 1 | from smog.common.command import CommandBase 2 | from smog.logger import Logger, console 3 | 4 | from smog import database 5 | 6 | 7 | class Add(CommandBase): 8 | 9 | command = "add" 10 | aliases = ["insert"] 11 | description = "Add data to the database" 12 | 13 | def init_arguments(self): 14 | self.parser.add_argument( 15 | "table", 16 | help="Table to add data to", 17 | choices={table.name for table in database.tables}, 18 | ) 19 | 20 | self.parser.add_argument("data", help="Data to add") 21 | 22 | def execute(self): 23 | table = self.database.get_table_by_str(self.arguments.table) 24 | 25 | if table is None: 26 | return Logger.warn(f"Table '{self.arguments.table}' does not exist.") 27 | 28 | data = ( 29 | console.input(f"Enter {table.name}: ") 30 | if self.arguments.data == "?" 31 | else self.arguments.data 32 | ) 33 | 34 | self.database.insert_data(table(data)) 35 | -------------------------------------------------------------------------------- /commands/clear.py: -------------------------------------------------------------------------------- 1 | import smog.banner 2 | 3 | from smog.common.command import CommandBase 4 | from smog.logger import console 5 | 6 | 7 | class Clear(CommandBase): 8 | 9 | command = "clear" 10 | description = "Clear the screen" 11 | aliases = ["cls"] 12 | 13 | def init_arguments(self): 14 | self.parser.add_argument( 15 | "-d", 16 | help="Enable banner printing", 17 | action="store_true", 18 | required=False, 19 | dest="print_banner", 20 | ) 21 | 22 | def execute(self): 23 | console.clear() 24 | 25 | if self.arguments.print_banner: 26 | console.print(smog.banner.BANNER) 27 | -------------------------------------------------------------------------------- /commands/credits.py: -------------------------------------------------------------------------------- 1 | from smog.common.command import CommandBase 2 | from smog.logger import console 3 | 4 | from rich.markdown import Markdown 5 | 6 | CREDITS = r""" 7 | # Smog Credits 8 | 9 | ## Developer 10 | * github.com/traumatism 11 | 12 | ## Others 13 | 14 | _Concept -> sn0int, github.com/kpcyrd/sn0int_ 15 | """ 16 | 17 | 18 | class Credits(CommandBase): 19 | 20 | command = "credits" 21 | description = "Show credits" 22 | 23 | def init_arguments(self): 24 | pass 25 | 26 | def execute(self): 27 | console.print(Markdown(CREDITS), width=80) 28 | -------------------------------------------------------------------------------- /commands/delete.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | from smog.common.command import CommandBase 4 | 5 | 6 | class Delete(CommandBase): 7 | 8 | command = "delete" 9 | aliases = ("del", "remove") 10 | description = "Remove data from a table" 11 | 12 | def init_arguments(self): 13 | self.parser.add_argument( 14 | "table", 15 | help="Table to add data to", 16 | choices={table.name for table in self.database.tables}, 17 | ) 18 | 19 | self.parser.add_argument( 20 | "id", help="ID of the data to delete", type=str, metavar="id" 21 | ) 22 | 23 | def test(self): 24 | """Testing syntax""" 25 | ids = [] 26 | 27 | if re.match(r"\d+<=i<=\d+", self.arguments.id): 28 | ids = self.arguments.id.split("<=") 29 | ids = list(map(int, ids)) 30 | 31 | if re.match(r"\d+>=i>=\d+", self.arguments.id): 32 | ids = self.arguments.id.split(">=") 33 | ids = list(map(int, ids)) 34 | 35 | if re.match(r"i==\d+", self.arguments.id): 36 | ids = self.arguments.id.split("<=") 37 | ids = list(map(int, ids)) 38 | 39 | if re.match(r"i!=\d+", self.arguments.id): 40 | ids = self.arguments.id.split("!=") 41 | 42 | for i in ids: 43 | self.database.delete_data(self.arguments.table, i) 44 | 45 | def execute(self): 46 | self.database.delete_data(self.arguments.table, int(self.arguments.id)) 47 | -------------------------------------------------------------------------------- /commands/export.py: -------------------------------------------------------------------------------- 1 | from smog.common.command import CommandBase 2 | from smog.logger import Logger 3 | 4 | 5 | class Export(CommandBase): 6 | 7 | command = "export" 8 | aliases = ["save"] 9 | description = "Export database to a .smog file" 10 | 11 | def init_arguments(self): 12 | self.parser.add_argument("file", help="File to export the DB to") 13 | self.parser.add_argument( 14 | "-q", "--quiet", help="Export silently", action="store_true" 15 | ) 16 | 17 | def execute(self): 18 | if self.database.is_empty is True: 19 | Logger.warn("The database is empty.") 20 | 21 | self.database.export_db(self.arguments.file, self.arguments.quiet) 22 | -------------------------------------------------------------------------------- /commands/help.py: -------------------------------------------------------------------------------- 1 | from rich.table import Table 2 | from rich.box import ASCII2 3 | 4 | from smog.common.command import CommandBase 5 | 6 | 7 | class Help(CommandBase): 8 | 9 | command = "help" 10 | description = "Show help menu" 11 | aliases = ("h", "?") 12 | 13 | def init_arguments(self): 14 | self.parser.add_argument( 15 | "-f", 16 | help="Print full help", 17 | action="store_true", 18 | required=False, 19 | dest="print_full", 20 | ) 21 | 22 | def execute(self): 23 | 24 | if self.arguments.print_full: 25 | for command in self.shell.commands: 26 | 27 | command_cls = command((), self.shell, self.console, self.database) 28 | command_cls.init_arguments() 29 | 30 | panel = command_cls.parser.print_help() 31 | 32 | self.console.print(panel) 33 | return 34 | 35 | table = Table(box=ASCII2) 36 | 37 | table.add_column("Command", style="bold white") 38 | table.add_column("Description", style="bold white") 39 | table.add_column("Aliases", style="bold white") 40 | 41 | for command in self.shell.commands: 42 | table.add_row( 43 | command.command, 44 | command.description, 45 | ", ".join(command.aliases) if command.aliases else "-", 46 | ) 47 | 48 | self.console.print(table) 49 | -------------------------------------------------------------------------------- /commands/load.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from smog.common.command import CommandBase 4 | 5 | 6 | class Load(CommandBase): 7 | 8 | command = "load" 9 | aliases = ["import"] 10 | description = "Import database from a .smog file" 11 | _arguments = {path for path in os.listdir(".") if path.endswith(".smog")} 12 | 13 | def init_arguments(self): 14 | self.parser.add_argument("file", help="File to import the DB from") 15 | 16 | def execute(self): 17 | self.database.import_db(self.arguments.file) 18 | -------------------------------------------------------------------------------- /commands/quit.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from rich.prompt import Prompt 4 | 5 | from smog.common.command import CommandBase 6 | 7 | 8 | class Quit(CommandBase): 9 | 10 | command = "quit" 11 | description = "Exit Smog" 12 | aliases = ("leave", "exit", "q") 13 | 14 | def init_arguments(self): 15 | pass 16 | 17 | def execute(self): 18 | response = Prompt.ask("Are you sure you want to exit? ", choices=["y", "n"]) 19 | 20 | if response == "y": 21 | sys.exit(0) 22 | -------------------------------------------------------------------------------- /commands/run.py: -------------------------------------------------------------------------------- 1 | from smog.common.command import CommandBase 2 | from smog.logger import Logger 3 | 4 | 5 | class Run(CommandBase): 6 | 7 | command = "run" 8 | description = "Run the selected module" 9 | aliases = ("execute", "start") 10 | 11 | def init_arguments(self): 12 | self.parser.add_argument( 13 | "-t", 14 | "--threads", 15 | type=int, 16 | default=5, 17 | help="Number of threads to run", 18 | metavar="", 19 | ) 20 | 21 | self.parser.add_argument( 22 | "-d", "--debug-threads", action="store_true", help="Debug threads" 23 | ) 24 | 25 | def execute(self): 26 | if self.shell.selected_module is None: 27 | return Logger.warn("No module selected.") 28 | 29 | self.shell.selected_module( 30 | self.database, self.arguments.threads, self.arguments.debug_threads 31 | )._execute() 32 | 33 | Logger.success("Done.") 34 | -------------------------------------------------------------------------------- /commands/search.py: -------------------------------------------------------------------------------- 1 | from rich.table import Table 2 | from rich.box import ASCII2 3 | 4 | from smog.common.command import CommandBase 5 | 6 | 7 | class Search(CommandBase): 8 | 9 | command = "search" 10 | description = "Search a module" 11 | 12 | def init_arguments(self): 13 | self.parser.add_argument("query", help="Query to search") 14 | 15 | def execute(self): 16 | table = Table(box=ASCII2) 17 | 18 | table.add_column("Module", style="bold white") 19 | table.add_column("Version", style="bold white") 20 | table.add_column("Description", style="bold white") 21 | table.add_column("Author", style="bold white") 22 | 23 | query = self.arguments.query.lower() 24 | 25 | for module in self.shell.modules: 26 | if query in module.name.lower() or query in module.description.lower(): 27 | table.add_row( 28 | module.name, 29 | module.version, 30 | module.description, 31 | module.author, 32 | ) 33 | 34 | self.console.print(table) 35 | -------------------------------------------------------------------------------- /commands/select.py: -------------------------------------------------------------------------------- 1 | from rich.table import Table 2 | from rich.box import ASCII2 3 | 4 | from smog import database 5 | 6 | from smog.common.command import CommandBase 7 | from smog.logger import Logger 8 | 9 | 10 | class Select(CommandBase): 11 | 12 | command = "select" 13 | description = "Select datas from the database" 14 | 15 | def init_arguments(self): 16 | self.parser.add_argument( 17 | "table", 18 | help="Table name", 19 | choices={table.full_name for table in database.tables}, 20 | ) 21 | 22 | def execute(self): 23 | data = self.database.select_data(self.arguments.table) 24 | 25 | if data is False: 26 | return Logger.warn("Table does not exist.") 27 | 28 | if data is []: 29 | return Logger.warn("Table is empty.") 30 | 31 | table = Table(box=ASCII2) 32 | 33 | table.add_column("#", style="bold bright_black") 34 | table.add_column("Value", style="bold white") 35 | table.add_column("Sub-data", style="bold white") 36 | 37 | for i, j in data.items(): 38 | table.add_row(str(i), j.value, str(j.sub_data)) 39 | 40 | self.console.print(table) 41 | -------------------------------------------------------------------------------- /commands/set.py: -------------------------------------------------------------------------------- 1 | from smog.common.command import CommandBase 2 | from smog.logger import Logger 3 | 4 | from smog import VARIABLES 5 | 6 | 7 | class Set(CommandBase): 8 | 9 | command = "set" 10 | description = "Set a variable to a value" 11 | 12 | def init_arguments(self): 13 | self.parser.add_argument( 14 | "variable", 15 | help="Variable to affect", 16 | choices=set(VARIABLES.keys()), 17 | ) 18 | 19 | self.parser.add_argument("value", help="Value to set variable to", nargs="*") 20 | 21 | def execute(self): 22 | value = " ".join(self.arguments.value) 23 | tmp = VARIABLES[self.arguments.variable][1] 24 | 25 | if tmp is not None and value not in tmp: 26 | return Logger.error(f"Invalid value for variable. (choose from {tmp})") 27 | 28 | VARIABLES[self.arguments.variable] = (value, tmp) 29 | 30 | return Logger.success(f"Variable set to '{value}'") 31 | -------------------------------------------------------------------------------- /commands/show.py: -------------------------------------------------------------------------------- 1 | from rich.table import Table 2 | from rich.box import ASCII2 3 | 4 | from smog import VARIABLES 5 | 6 | from smog.logger import Logger 7 | from smog.common.command import CommandBase 8 | 9 | 10 | class Show(CommandBase): 11 | 12 | command = "show" 13 | description = "Show somethin'" 14 | 15 | def init_arguments(self): 16 | self.parser.add_argument( 17 | "type", 18 | help="Thing to show", 19 | choices=("stats", "modules", "tables", "variables"), 20 | ) 21 | 22 | def execute(self): 23 | table = Table(box=ASCII2) 24 | 25 | if self.arguments.type == "stats": 26 | 27 | table.add_column("Type", style="bold white") 28 | table.add_column("%", style="bold white") 29 | table.add_column("Count", style="bold white") 30 | 31 | try: 32 | for _table, percents, count in self.database.stats: 33 | table.add_row( 34 | _table.description.lower(), *map(str, (percents, count)) 35 | ) 36 | 37 | except ZeroDivisionError: 38 | Logger.error("Database is empty.") 39 | 40 | if self.arguments.type == "modules": 41 | 42 | table.add_column("Module", style="bold white") 43 | table.add_column("Version", style="bold white") 44 | table.add_column("Description", style="bold white") 45 | table.add_column("Author", style="bold white") 46 | 47 | for module in self.shell.modules: 48 | table.add_row( 49 | module.name, 50 | module.version, 51 | module.description, 52 | module.author, 53 | ) 54 | 55 | if self.arguments.type == "variables": 56 | 57 | table.add_column("Variable", style="bold white") 58 | table.add_column("Value", style="bold white") 59 | 60 | for v, _v in VARIABLES.items(): 61 | table.add_row(v, _v[0]) 62 | 63 | if self.arguments.type == "tables": 64 | 65 | table.add_column("Table", style="bold white") 66 | table.add_column("Description", style="bold white") 67 | table.add_column("Alias", style="bold white") 68 | 69 | for _table in self.database.tables: 70 | table.add_row(_table.full_name, _table.description, _table.name) 71 | 72 | return self.console.print(table) 73 | -------------------------------------------------------------------------------- /commands/use.py: -------------------------------------------------------------------------------- 1 | from smog import MODULES 2 | from smog.logger import Logger 3 | from smog.common.command import CommandBase 4 | 5 | 6 | class Use(CommandBase): 7 | 8 | command = "use" 9 | description = "Select a module to use" 10 | 11 | def init_arguments(self): 12 | self.parser.add_argument( 13 | "module", 14 | help="Module name", 15 | choices={module.name for module in MODULES}, 16 | ) 17 | 18 | def execute(self): 19 | module = self.shell.modules_map.get(self.arguments.module, None) 20 | 21 | if module is None: 22 | return Logger.warn(f"Module '{self.arguments.module}' not found.") 23 | 24 | self.shell.selected_module = module 25 | -------------------------------------------------------------------------------- /images/module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Traumatism/Smog/397658a4743c3ed5ff2d0d837feef1e55d9a556f/images/module.png -------------------------------------------------------------------------------- /images/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Traumatism/Smog/397658a4743c3ed5ff2d0d837feef1e55d9a556f/images/preview.png -------------------------------------------------------------------------------- /modules/crtsh.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | from smog import module 4 | from smog.common.module import ABC 5 | from smog.database.types.subdomain import Subdomain 6 | 7 | 8 | @module 9 | class Module(ABC): 10 | name = "crtsh" 11 | version = "0.0.1" 12 | author = "toastakerman" 13 | description = "Search subdomains on CRT.sh" 14 | keywords = ["crtsh", "certificates", "subdomains", "scanning"] 15 | 16 | def sub_action(self, domain): 17 | with requests.get( 18 | "https://crt.sh/?q=%(domain)s&output=json" % {"domain": domain} 19 | ) as response: 20 | json_data = response.json() 21 | 22 | if not json_data: 23 | return 24 | 25 | for data in json_data: 26 | if (value := data.get("name_value", None)) is None: 27 | continue 28 | 29 | for part in value.split("\n"): 30 | if not part.endswith(domain) or part.startswith("*") or part == domain: 31 | continue 32 | 33 | self.database.insert_data(Subdomain(part)) 34 | 35 | def execute(self): 36 | for _, target in (self.database.select_data("domains") or {}).items(): 37 | self.respect_threads_run((target.value,)) 38 | -------------------------------------------------------------------------------- /modules/dbs.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | from rich.progress import Progress 4 | 5 | from smog import module 6 | from smog.database.types.databaseserver import DatabaseServer 7 | from smog.common.module import ABC 8 | from smog.logger import Logger, console 9 | 10 | ENGINES = { 11 | "MySQL": 3306, 12 | "PgSQL": 5432, 13 | "MongoDB": 27017, 14 | "Redis": 6379, 15 | "Memcached": 11211, 16 | "MsSQL": 1433, 17 | "InfluxDB": 8086, 18 | "Elasticsearch": 9200, 19 | } 20 | 21 | 22 | @module 23 | class Module(ABC): 24 | name = "dbs" 25 | description = "Search for databases servers using port scanning" 26 | author = "toastakerman" 27 | 28 | def sub_action(self, i, ip, port, engine): 29 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 30 | s.settimeout(3.5) 31 | 32 | try: 33 | s.connect((ip, port)) 34 | except socket.error: 35 | return 36 | 37 | Logger.success(f"Found potential {engine} server on '{ip}:{port}'.") 38 | 39 | self.database.update_subdata( 40 | "ip_addrs", 41 | i, 42 | engine.lower(), 43 | DatabaseServer((ip, port, "null", "null", "null", engine.lower())).export(), 44 | ) 45 | 46 | def execute(self): 47 | targets = { 48 | _: target 49 | for _, target in (self.database.select_data("ip_addrs") or {}).items() 50 | if target.sub_data.get("org", None) != "AS13335 Cloudflare, Inc." 51 | } 52 | 53 | with Progress(console=console) as progress: 54 | task = progress.add_task( 55 | "Scanning for databases", 56 | total=len(targets) * len(ENGINES.values()), 57 | ) 58 | 59 | for _, target in targets.items(): 60 | 61 | for engine, port in ENGINES.items(): 62 | self.respect_threads_run((_, target.value, port, engine)) 63 | progress.advance(task, 1) 64 | -------------------------------------------------------------------------------- /modules/hackertarget.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | from smog import module 4 | from smog.common.module import ABC 5 | from smog.database.types.subdomain import Subdomain 6 | from smog.database.types.ip_address import IPAddress 7 | 8 | 9 | @module 10 | class Module(ABC): 11 | name = "hackertarget" 12 | version = "0.0.1" 13 | author = "toastakerman" 14 | description = "Search subdomains on hackertarget.com" 15 | keywords = ["hackertarget", "subdomains", "ip addresses", "scanning"] 16 | 17 | def sub_action(self, domain): 18 | with requests.get( 19 | "https://api.hackertarget.com/hostsearch/?q=%(domain)s" % {"domain": domain} 20 | ) as response: 21 | html_content = response.text 22 | 23 | if "error invalid host" in html_content: 24 | return 25 | 26 | for line in html_content.splitlines(): 27 | parts = line.split(",") 28 | 29 | self.database.insert_data(Subdomain(parts[0])) 30 | self.database.insert_data(IPAddress(parts[1])) 31 | 32 | def execute(self): 33 | for _, target in (self.database.select_data("domains") or {}).items(): 34 | self.respect_threads_run((target.value,)) 35 | -------------------------------------------------------------------------------- /modules/ipinfo.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | from smog import module 4 | from smog.common.module import ABC 5 | from smog.database.types.ip_address import IPAddress 6 | 7 | 8 | @module 9 | class Module(ABC): 10 | name = "ipinfo" 11 | version = "0.0.1" 12 | author = "toastakerman" 13 | description = "Gather informations on IP addresses" 14 | category = "scanning" 15 | 16 | def sub_action(self, ip_address): 17 | with requests.get(f"https://ipinfo.io/{ip_address.value}/json") as response: 18 | json_data = response.json() 19 | 20 | if response.status_code != 200 or "bogon" in json_data: 21 | return 22 | 23 | _id = self.database.get_id_by_value(ip_address.value) 24 | 25 | try: 26 | self.database.update_subdata("ip_addrs", _id, "org", json_data["org"]) 27 | 28 | self.database.update_subdata( 29 | "ip_addrs", 30 | _id, 31 | "loc", 32 | {"country": json_data["country"], "city": json_data["city"]}, 33 | ) 34 | except KeyError: 35 | pass 36 | 37 | def execute(self): 38 | for _, target in (self.database.select_data("ip_addrs") or {}).items(): 39 | self.respect_threads_run((target,)) 40 | -------------------------------------------------------------------------------- /modules/phpmyadmin.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | from smog import module 4 | from smog.common.module import ABC 5 | from smog.database.types.url import URL 6 | 7 | from urllib3 import disable_warnings 8 | 9 | 10 | PHPMYADMIN_PATHS = ( 11 | "", 12 | "myadmin/", 13 | "PMA", 14 | "PMA/", 15 | "PMA/index.php", 16 | "PMA2/index.php", 17 | "__pma___", 18 | "admin/pMA/", 19 | "admin/pma/", 20 | "admin/PMA/index.php", 21 | "admin/pma/index.php", 22 | "administrator/PMA/", 23 | "administrator/pma/", 24 | "mysql/pMA/", 25 | "mysql/pma/", 26 | "PMA", 27 | "pma", 28 | "pma-old/index.php", 29 | "PMA/", 30 | "pma/", 31 | "PMA/index.php", 32 | "pma/index.php", 33 | "pma/scripts/setup.php", 34 | "PMA2/index.php", 35 | "PMA2005", 36 | "pma2005", 37 | "PMA2005/", 38 | "pma2005/", 39 | "PMA2009/", 40 | "pma2009/", 41 | "PMA2011/", 42 | "pma2011/", 43 | "PMA2012/", 44 | "pma2012/", 45 | "PMA2013/", 46 | "pma2013/", 47 | "PMA2014/", 48 | "pma2014/", 49 | "PMA2015/", 50 | "pma2015/", 51 | "PMA2016/", 52 | "pma2016/", 53 | "PMA2017/", 54 | "pma2017/", 55 | "PMA2018/", 56 | "pma2018/", 57 | "pma4/", 58 | "pmadmin", 59 | "pmadmin/", 60 | "pmamy/index.php", 61 | "pmamy2/index.php", 62 | "sql/phpmanager/", 63 | ".tools/phpMyAdmin/", 64 | ".tools/phpMyAdmin/current/", 65 | "2phpmyadmin/", 66 | "_LPHPMYADMIN/", 67 | "_phpmyadmin", 68 | "_phpmyadmin/", 69 | "admin/phpMyAdmin", 70 | "admin/phpMyAdmin/", 71 | "admin/phpmyadmin/", 72 | "admin/phpMyAdmin/index.php", 73 | "admin/phpmyadmin/index.php", 74 | "admin/phpmyadmin2/index.php", 75 | "administrator/phpMyAdmin/", 76 | "administrator/phpmyadmin/", 77 | "claroline/phpMyAdmin/index.php", 78 | "database/phpMyAdmin/", 79 | "database/phpmyadmin/", 80 | "database/phpMyAdmin2/", 81 | "database/phpmyadmin2/", 82 | "db/phpMyAdmin-2/", 83 | "db/phpMyAdmin-3/", 84 | "db/phpMyAdmin/", 85 | "db/phpmyadmin/", 86 | "db/phpMyAdmin2/", 87 | "db/phpmyadmin2/", 88 | "db/phpMyAdmin3/", 89 | "db/phpmyadmin3/", 90 | "phpmyadmin/ChangeLog", 91 | "phpmyadmin/doc/html/index.html", 92 | "phpmyadmin/docs/html/index.html", 93 | "phpmyadmin/README", 94 | "phpMyAdmin", 95 | "phpmyadmin", 96 | "phpmyadmin!!", 97 | "phpMyAdmin-2", 98 | "phpMyAdmin-2.10.0/", 99 | "phpMyAdmin-2.10.1/", 100 | "phpMyAdmin-2.10.2/", 101 | "phpMyAdmin-2.10.3/", 102 | "phpMyAdmin-2.11.0/", 103 | "phpMyAdmin-2.11.1/", 104 | "phpMyAdmin-2.11.10/", 105 | "phpMyAdmin-2.11.2/", 106 | "phpMyAdmin-2.11.3/", 107 | "phpMyAdmin-2.11.4/", 108 | "phpMyAdmin-2.11.5.1-all-languages/", 109 | "phpMyAdmin-2.11.5/", 110 | "phpMyAdmin-2.11.6-all-languages/", 111 | "phpMyAdmin-2.11.6/", 112 | "phpMyAdmin-2.11.7.1-all-languages-utf-8-only/", 113 | "phpMyAdmin-2.11.7.1-all-languages/", 114 | "phpMyAdmin-2.11.7/", 115 | "phpMyAdmin-2.11.8.1-all-languages-utf-8-only/", 116 | "phpMyAdmin-2.11.8.1-all-languages/", 117 | "phpMyAdmin-2.11.8.1/", 118 | "phpMyAdmin-2.11.9/", 119 | "phpMyAdmin-2.2.3", 120 | "phpMyAdmin-2.2.3/", 121 | "phpMyAdmin-2.2.6", 122 | "phpMyAdmin-2.2.6/", 123 | "phpMyAdmin-2.5.1", 124 | "phpMyAdmin-2.5.1/", 125 | "phpMyAdmin-2.5.4", 126 | "phpMyAdmin-2.5.4/", 127 | "phpMyAdmin-2.5.5", 128 | "phpMyAdmin-2.5.5-pl1", 129 | "phpMyAdmin-2.5.5-pl1/", 130 | "phpMyAdmin-2.5.5-rc1", 131 | "phpMyAdmin-2.5.5-rc1/", 132 | "phpMyAdmin-2.5.5-rc2", 133 | "phpMyAdmin-2.5.5-rc2/", 134 | "phpMyAdmin-2.5.5/", 135 | "phpMyAdmin-2.5.6", 136 | "phpMyAdmin-2.5.6-rc1", 137 | "phpMyAdmin-2.5.6-rc1/", 138 | "phpMyAdmin-2.5.6-rc2", 139 | "phpMyAdmin-2.5.6-rc2/", 140 | "phpMyAdmin-2.5.6/", 141 | "phpMyAdmin-2.5.7", 142 | "phpMyAdmin-2.5.7-pl1", 143 | "phpMyAdmin-2.5.7-pl1/", 144 | "phpMyAdmin-2.5.7/", 145 | "phpMyAdmin-2.6.0", 146 | "phpMyAdmin-2.6.0-alpha", 147 | "phpMyAdmin-2.6.0-alpha/", 148 | "phpMyAdmin-2.6.0-alpha2", 149 | "phpMyAdmin-2.6.0-alpha2/", 150 | "phpMyAdmin-2.6.0-beta1", 151 | "phpMyAdmin-2.6.0-beta1/", 152 | "phpMyAdmin-2.6.0-beta2", 153 | "phpMyAdmin-2.6.0-beta2/", 154 | "phpMyAdmin-2.6.0-pl1", 155 | "phpMyAdmin-2.6.0-pl1/", 156 | "phpMyAdmin-2.6.0-pl2", 157 | "phpMyAdmin-2.6.0-pl2/", 158 | "phpMyAdmin-2.6.0-pl3", 159 | "phpMyAdmin-2.6.0-pl3/", 160 | "phpMyAdmin-2.6.0-rc1", 161 | "phpMyAdmin-2.6.0-rc1/", 162 | "phpMyAdmin-2.6.0-rc2", 163 | "phpMyAdmin-2.6.0-rc2/", 164 | "phpMyAdmin-2.6.0-rc3", 165 | "phpMyAdmin-2.6.0-rc3/", 166 | "phpMyAdmin-2.6.0/", 167 | "phpMyAdmin-2.6.1", 168 | "phpMyAdmin-2.6.1-pl1", 169 | "phpMyAdmin-2.6.1-pl1/", 170 | "phpMyAdmin-2.6.1-pl2", 171 | "phpMyAdmin-2.6.1-pl2/", 172 | "phpMyAdmin-2.6.1-pl3", 173 | "phpMyAdmin-2.6.1-pl3/", 174 | "phpMyAdmin-2.6.1-rc1", 175 | "phpMyAdmin-2.6.1-rc1/", 176 | "phpMyAdmin-2.6.1-rc2", 177 | "phpMyAdmin-2.6.1-rc2/", 178 | "phpMyAdmin-2.6.1/", 179 | "phpMyAdmin-2.6.2", 180 | "phpMyAdmin-2.6.2-beta1", 181 | "phpMyAdmin-2.6.2-beta1/", 182 | "phpMyAdmin-2.6.2-pl1", 183 | "phpMyAdmin-2.6.2-pl1/", 184 | "phpMyAdmin-2.6.2-rc1", 185 | "phpMyAdmin-2.6.2-rc1/", 186 | "phpMyAdmin-2.6.2/", 187 | "phpMyAdmin-2.6.3", 188 | "phpMyAdmin-2.6.3-pl1", 189 | "phpMyAdmin-2.6.3-pl1/", 190 | "phpMyAdmin-2.6.3-rc1", 191 | "phpMyAdmin-2.6.3-rc1/", 192 | "phpMyAdmin-2.6.3/", 193 | "phpMyAdmin-2.6.4", 194 | "phpMyAdmin-2.6.4-pl1", 195 | "phpMyAdmin-2.6.4-pl1/", 196 | "phpMyAdmin-2.6.4-pl2", 197 | "phpMyAdmin-2.6.4-pl2/", 198 | "phpMyAdmin-2.6.4-pl3", 199 | "phpMyAdmin-2.6.4-pl3/", 200 | "phpMyAdmin-2.6.4-pl4", 201 | "phpMyAdmin-2.6.4-pl4/", 202 | "phpMyAdmin-2.6.4-rc1", 203 | "phpMyAdmin-2.6.4-rc1/", 204 | "phpMyAdmin-2.6.4/", 205 | "phpMyAdmin-2.7.0", 206 | "phpMyAdmin-2.7.0-beta1", 207 | "phpMyAdmin-2.7.0-beta1/", 208 | "phpMyAdmin-2.7.0-pl1", 209 | "phpMyAdmin-2.7.0-pl1/", 210 | "phpMyAdmin-2.7.0-pl2", 211 | "phpMyAdmin-2.7.0-pl2/", 212 | "phpMyAdmin-2.7.0-rc1", 213 | "phpMyAdmin-2.7.0-rc1/", 214 | "phpMyAdmin-2.7.0/", 215 | "phpMyAdmin-2.8.0", 216 | "phpMyAdmin-2.8.0-beta1", 217 | "phpMyAdmin-2.8.0-beta1/", 218 | "phpMyAdmin-2.8.0-rc1", 219 | "phpMyAdmin-2.8.0-rc1/", 220 | "phpMyAdmin-2.8.0-rc2", 221 | "phpMyAdmin-2.8.0-rc2/", 222 | "phpMyAdmin-2.8.0.1", 223 | "phpMyAdmin-2.8.0.1/", 224 | "phpMyAdmin-2.8.0.2", 225 | "phpMyAdmin-2.8.0.2/", 226 | "phpMyAdmin-2.8.0.3", 227 | "phpMyAdmin-2.8.0.3/", 228 | "phpMyAdmin-2.8.0.4", 229 | "phpMyAdmin-2.8.0.4/", 230 | "phpMyAdmin-2.8.0/", 231 | "phpMyAdmin-2.8.1", 232 | "phpMyAdmin-2.8.1-rc1", 233 | "phpMyAdmin-2.8.1-rc1/", 234 | "phpMyAdmin-2.8.1/", 235 | "phpMyAdmin-2.8.2", 236 | "phpMyAdmin-2.8.2/", 237 | "phpMyAdmin-2/", 238 | "phpMyAdmin-3.0.0/", 239 | "phpMyAdmin-3.0.1/", 240 | "phpMyAdmin-3.1.0/", 241 | "phpMyAdmin-3.1.1/", 242 | "phpMyAdmin-3.1.2/", 243 | "phpMyAdmin-3.1.3/", 244 | "phpMyAdmin-3.1.4/", 245 | "phpMyAdmin-3.1.5/", 246 | "phpMyAdmin-3.2.0/", 247 | "phpMyAdmin-3.2.1/", 248 | "phpMyAdmin-3.2.2/", 249 | "phpMyAdmin-3.2.3/", 250 | "phpMyAdmin-3.2.4/", 251 | "phpMyAdmin-3.2.5/", 252 | "phpMyAdmin-3.3.0/", 253 | "phpMyAdmin-3.3.1/", 254 | "phpMyAdmin-3.3.2-rc1/", 255 | "phpMyAdmin-3.3.2/", 256 | "phpMyAdmin-3.3.3-rc1/", 257 | "phpMyAdmin-3.3.3/", 258 | "phpMyAdmin-3.3.4-rc1/", 259 | "phpMyAdmin-3.3.4/", 260 | "phpMyAdmin-3/", 261 | "phpMyAdmin-4/", 262 | "phpmyadmin-old", 263 | "phpmyadmin-old/index.php", 264 | "phpMyAdmin.old/index.php", 265 | "phpMyAdmin/", 266 | "phpMyadmin/", 267 | "phpmyAdmin/", 268 | "phpmyadmin/", 269 | "phpMyAdmin/index.php", 270 | "phpmyadmin/index.php", 271 | "phpMyAdmin/phpMyAdmin/index.php", 272 | "phpmyadmin/phpmyadmin/index.php", 273 | "phpMyAdmin/scripts/setup.php", 274 | "phpmyadmin/scripts/setup.php", 275 | "phpMyAdmin0/", 276 | "phpmyadmin0/", 277 | "phpmyadmin0/index.php", 278 | "phpMyAdmin1/", 279 | "phpmyadmin1/", 280 | "phpmyadmin1/index.php", 281 | "phpMyAdmin2", 282 | "phpmyadmin2", 283 | "phpMyAdmin2/", 284 | "phpmyadmin2/", 285 | "phpmyadmin2/index.php", 286 | "phpmyadmin2011/", 287 | "phpmyadmin2012/", 288 | "phpmyadmin2013/", 289 | "phpmyadmin2014/", 290 | "phpmyadmin2015/", 291 | "phpmyadmin2016/", 292 | "phpmyadmin2017/", 293 | "phpmyadmin2018/", 294 | "phpmyadmin3", 295 | "phpMyAdmin3/", 296 | "phpmyadmin3/", 297 | "phpMyAdmin4/", 298 | "phpmyadmin4/", 299 | "phpMyadmin_bak/index.php", 300 | "phpMyAdminBackup/", 301 | "phpMyAdminold/index.php", 302 | "sql/phpMyAdmin/", 303 | "sql/phpMyAdmin2/", 304 | "sql/phpmyadmin2/", 305 | "tools/phpMyAdmin/index.php", 306 | "typo3/phpmyadmin/", 307 | "typo3/phpmyadmin/index.php", 308 | "typo3/phpmyadmin/scripts/setup.php", 309 | "uber/phpMyAdmin/", 310 | "uber/phpMyAdminBackup/", 311 | "web/phpMyAdmin/", 312 | "web/phpMyAdmin/index.php", 313 | "web/phpMyAdmin/scripts/setup.php", 314 | "www/phpMyAdmin/index.php", 315 | "xampp/phpmyadmin/", 316 | "xampp/phpmyadmin/index.php", 317 | "xampp/phpmyadmin/scripts/setup.php", 318 | "xphpMyAdmin/", 319 | ) 320 | 321 | disable_warnings() 322 | 323 | 324 | @module 325 | class Module(ABC): 326 | name = "phpmyadmin" 327 | description = "Search for phpmyadmin in the URLs" 328 | author = "toastakerman" 329 | 330 | def sub_action(self, target): 331 | for path in PHPMYADMIN_PATHS: 332 | try: 333 | response = requests.get(f"{target}/{path}", verify=False, timeout=5) 334 | except Exception: 335 | continue 336 | 337 | if "phpmyadmin" in response.text.lower() and response.status_code != 404: 338 | self.database.insert_data(URL(response.url)) 339 | 340 | def execute(self): 341 | for _, target in (self.database.select_data("urls") or {}).items(): 342 | self.respect_threads_run((target,)) 343 | -------------------------------------------------------------------------------- /modules/resolve.py: -------------------------------------------------------------------------------- 1 | import dns.resolver 2 | 3 | from smog import module 4 | from smog.common.module import ABC 5 | from smog.database.types.ip_address import IPAddress 6 | 7 | 8 | @module 9 | class Module(ABC): 10 | name = "resolve" 11 | version = "0.0.1" 12 | author = "toastakerman" 13 | description = "Resolve subdomains to IP addresses" 14 | category = "resolving" 15 | 16 | def sub_action(self, target): 17 | try: 18 | answers = dns.resolver.resolve(target, "A") 19 | 20 | for answer in answers: 21 | self.database.insert_data(IPAddress(answer.address)) 22 | 23 | addr = ( 24 | self.database.select_data( 25 | "ip_addrs", self.database.get_id_by_value(answer.address) 26 | ) 27 | or answer.address 28 | ) 29 | 30 | if isinstance(addr, str) is False: 31 | addr = list(addr.values())[0].export() 32 | 33 | self.database.update_subdata( 34 | "subdomains", self.database.get_id_by_value(target), "ip_addr", addr 35 | ) 36 | 37 | except Exception: 38 | pass 39 | 40 | def execute(self): 41 | targets = self.database.select_data("subdomains") or {} 42 | 43 | for _, target in targets.items(): 44 | self.respect_threads_run((target.value,)) 45 | -------------------------------------------------------------------------------- /modules/urlscan.py: -------------------------------------------------------------------------------- 1 | import contextlib 2 | import requests 3 | 4 | from smog import module 5 | from smog.common.module import ABC 6 | from smog.database.types.url import URL 7 | 8 | from urllib3 import disable_warnings 9 | 10 | disable_warnings() 11 | 12 | 13 | @module 14 | class Module(ABC): 15 | name = "urlscan" 16 | description = "Scan subdomains/IP addresses for HTTP(s) protocols" 17 | author = "toastakerman" 18 | keywords = ["urlscan", "url", "scan", "http", "https", "subdomain"] 19 | 20 | def sub_action(self, target, scheme): 21 | with contextlib.suppress(requests.RequestException): 22 | response = requests.get(f"{scheme}://{target}/", verify=False, timeout=5) 23 | 24 | _id = self.database.insert_data(URL(f"{scheme}://{target}/")) 25 | 26 | self.database.update_subdata("urls", _id, "body", response.text) 27 | self.database.update_subdata("urls", _id, "headers", response.headers) 28 | 29 | def execute(self): 30 | targets = self.database.select_data("subdomains") or {} 31 | 32 | for _, target in targets.items(): 33 | for scheme in ("http", "https"): 34 | self.respect_threads_run(args=(target.value, scheme)) 35 | 36 | targets = self.database.select_data("ip_addrs") or {} 37 | 38 | for _, target in targets.items(): 39 | for scheme in ("http", "https"): 40 | self.respect_threads_run(args=(target.value, scheme)) 41 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | dnspython==2.1.0 2 | requests==2.31.0 3 | requests-toolbelt==0.9.1 4 | rich==10.14.0 5 | prompt_toolkit 6 | -------------------------------------------------------------------------------- /smog/__init__.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | import glob 3 | import json 4 | import os 5 | 6 | from typing import List, Type 7 | 8 | PATH = os.path.join(os.path.expanduser("~"), ".smog.json") 9 | 10 | if not os.path.exists(PATH) or not os.path.isfile(PATH): 11 | if os.path.exists(PATH): 12 | os.remove(PATH) 13 | 14 | with open(PATH, "a+") as f: 15 | f.write("{}") 16 | 17 | while True: 18 | try: 19 | with open(PATH, "r") as f: 20 | CONFIG = json.load(f) 21 | break 22 | except FileExistsError: 23 | os.remove(PATH) 24 | with open(PATH, "a+") as f: 25 | f.write("{}") 26 | 27 | 28 | VARIABLES = { 29 | "prompt-char": (">", ("$", ">", "#", ":")), 30 | "shodan-key": ("null", None), 31 | "workspace_name": ("default", None), 32 | "exceptions_debug": ("false", ("false", "true")), 33 | "user-agent": ("Mozilla/5.0", None), 34 | } 35 | 36 | __version__ = "1.3" 37 | 38 | from smog.database import database 39 | from smog.common.module import ModuleBase 40 | 41 | MODULES: List[Type[ModuleBase]] = [] 42 | module = MODULES.append 43 | 44 | modules_files = list( 45 | map(lambda path: "modules." + path[8:][:-3], glob.glob("modules/*.py")) 46 | ) 47 | 48 | 49 | list(map(importlib.import_module, modules_files)) 50 | 51 | from commands.credits import Credits 52 | from commands.select import Select 53 | from commands.delete import Delete 54 | from commands.export import Export 55 | from commands.load import Load 56 | from commands.clear import Clear 57 | from commands.help import Help 58 | from commands.show import Show 59 | from commands.quit import Quit 60 | from commands.use import Use 61 | from commands.run import Run 62 | from commands.add import Add 63 | from commands.set import Set 64 | from commands.search import Search 65 | 66 | COMMANDS = { 67 | Help, 68 | Clear, 69 | Show, 70 | Use, 71 | Run, 72 | Select, 73 | Add, 74 | Delete, 75 | Export, 76 | Load, 77 | Set, 78 | Credits, 79 | Search, 80 | Quit, 81 | } 82 | 83 | from smog.shell import Shell 84 | 85 | shell = Shell() 86 | -------------------------------------------------------------------------------- /smog/__main__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from smog import shell 4 | from smog.logger import Logger 5 | 6 | if __name__ == "__main__": 7 | if len(sys.argv) == 2: 8 | shell.project_name = sys.argv[1] 9 | 10 | try: 11 | shell.run() 12 | except (KeyboardInterrupt, EOFError): 13 | shell.handle_command_line("quit") 14 | -------------------------------------------------------------------------------- /smog/api/crypto.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Traumatism/Smog/397658a4743c3ed5ff2d0d837feef1e55d9a556f/smog/api/crypto.py -------------------------------------------------------------------------------- /smog/api/dns.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Traumatism/Smog/397658a4743c3ed5ff2d0d837feef1e55d9a556f/smog/api/dns.py -------------------------------------------------------------------------------- /smog/api/http.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Traumatism/Smog/397658a4743c3ed5ff2d0d837feef1e55d9a556f/smog/api/http.py -------------------------------------------------------------------------------- /smog/banner.py: -------------------------------------------------------------------------------- 1 | from smog import __version__ 2 | 3 | __all__ = ("BANNER",) 4 | 5 | BANNER = ( 6 | r""" 7 | [reset] 8 | ______ __ __ ______ ______ 9 | /\ ___\ /\ "-./ \ /\ __ \ /\ ___\ 10 | \ \___ \ \ \ \-./\ \ \ \ \/\ \ \ \ \__ \ 11 | \/\_____\ \ \_\ \ \_\ \ \_____\ \ \_____\ 12 | \/_____/ \/_/ \/_/ \/_____/ \/_____/ [bright_black]v%s[/] 13 | [/] 14 | """ 15 | % __version__ 16 | ) 17 | -------------------------------------------------------------------------------- /smog/common/command.py: -------------------------------------------------------------------------------- 1 | from argparse import Namespace 2 | from typing import Iterable, Any 3 | from rich.console import Console 4 | from abc import ABCMeta, abstractmethod 5 | 6 | from smog.database.database import Database 7 | from smog.utils.arguments import ArgumentParser 8 | 9 | 10 | class CommandBase(metaclass=ABCMeta): 11 | """Abstract class for commands""" 12 | 13 | command: str = "" 14 | description: str = "" 15 | aliases: Iterable[str] = [] 16 | _arguments: Iterable[Any] = {} 17 | 18 | def __init__( 19 | self, 20 | raw_arguments: Iterable[str], 21 | shell, # can't import Shell due to circular imports, llo 22 | console: Console, 23 | database: Database, 24 | ): 25 | self.shell = shell 26 | self.console = console 27 | self.database = database 28 | self.raw_arguments = raw_arguments 29 | 30 | self.parser = ArgumentParser( 31 | description=self.description, usage=f"{self.command} " 32 | ) 33 | 34 | self.arguments = Namespace() 35 | 36 | @abstractmethod 37 | def init_arguments(self): 38 | """Initialize command arguments""" 39 | 40 | @abstractmethod 41 | def execute(self): 42 | """Execute the command""" 43 | -------------------------------------------------------------------------------- /smog/common/module.py: -------------------------------------------------------------------------------- 1 | import threading as _threading 2 | 3 | from abc import ABCMeta, abstractmethod 4 | 5 | from typing import Iterable, Optional 6 | 7 | from smog.database.database import Database 8 | from smog.logger import Logger 9 | 10 | 11 | class ModuleBase(metaclass=ABCMeta): 12 | """Abstract class for modules""" 13 | 14 | name: str 15 | version: str = "0.0.1" 16 | author: str = "" 17 | description: str = "" 18 | category: str = "" 19 | keywords: Iterable[str] = [] 20 | 21 | def __init__(self, database: Database, threads: int, debug_threads: bool): 22 | self.debug_threads = debug_threads 23 | self.database = database 24 | self.threads = threads 25 | self.__action = 0 26 | 27 | @abstractmethod 28 | def sub_action(self, *args): 29 | """This function gonna be ran with threading""" 30 | 31 | def _sub_action(self, i, args=()): 32 | """Run sub-action""" 33 | if self.debug_threads: 34 | Logger.info(f"Running subaction #{i}...") 35 | 36 | self.sub_action(*args) 37 | 38 | if self.debug_threads: 39 | Logger.success(f"Subaction #{i} finished.") 40 | 41 | def respect_threads_run(self, args: Iterable | None = None): 42 | """Run a function with respect to max threads""" 43 | if args is None: 44 | args = [] 45 | 46 | while True: 47 | if _threading.active_count() <= self.threads: 48 | self.__action += 1 49 | 50 | return _threading.Thread( 51 | target=self._sub_action, args=(self.__action, args) 52 | ).start() 53 | 54 | def wait_for_finish(self): 55 | """Wait for threads to finish""" 56 | if self.debug_threads: 57 | Logger.info("Waiting for threads to finish...") 58 | 59 | while _threading.active_count() > 1: 60 | pass 61 | 62 | self.__action = 0 63 | 64 | def _execute(self): 65 | self.execute() 66 | self.wait_for_finish() 67 | 68 | @abstractmethod 69 | def execute(self): 70 | """Execute the module""" 71 | 72 | 73 | ABC = ModuleBase 74 | -------------------------------------------------------------------------------- /smog/common/type.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta, abstractmethod 2 | 3 | from typing import Any, Dict, Tuple 4 | 5 | 6 | class Type(metaclass=ABCMeta): 7 | """Abstract class for database types""" 8 | 9 | name = "" 10 | full_name = "" 11 | description = "" 12 | 13 | def __init__(self, value: Any): 14 | self.value = value 15 | self.sub_data: Dict[str, Any] = {} 16 | 17 | def export(self) -> Tuple[Any, Dict]: 18 | """Export the data to a tuple""" 19 | return self.value, self.sub_data 20 | 21 | @abstractmethod 22 | def validate(self) -> bool: 23 | """Validate the value""" 24 | raise NotImplementedError 25 | -------------------------------------------------------------------------------- /smog/database/__init__.py: -------------------------------------------------------------------------------- 1 | from .database import Database 2 | 3 | database = Database() 4 | -------------------------------------------------------------------------------- /smog/database/database.py: -------------------------------------------------------------------------------- 1 | import hashlib 2 | import pickle 3 | import base64 4 | 5 | from typing import Dict, Iterable, List, Literal, Union, Tuple, Optional 6 | from typing import Type as _Type 7 | 8 | from smog.common.type import Type 9 | from smog.logger import Logger 10 | 11 | from smog.database.types import ( 12 | Domain, 13 | IPAddress, 14 | Port, 15 | Subdomain, 16 | URL, 17 | Email, 18 | Phone, 19 | Social, 20 | ) 21 | 22 | DatabaseType = _Type[Type] 23 | DatabaseDict = Dict[DatabaseType, Dict[int, Type]] 24 | 25 | 26 | class Database: 27 | """Primitive database class for Smog""" 28 | 29 | def __init__(self) -> None: 30 | 31 | self.__tables = { 32 | IPAddress, 33 | Domain, 34 | Subdomain, 35 | URL, 36 | Email, 37 | Phone, 38 | Social, 39 | Port, 40 | } 41 | 42 | self.__database: DatabaseDict = { 43 | table: {} for table in self.__tables if issubclass(table, Type) # type: ignore 44 | } 45 | 46 | self.saved = False 47 | self.last_sum_saved = self.md5sum 48 | 49 | @property 50 | def md5sum(self) -> str: 51 | """Return the database md5 sum""" 52 | return hashlib.md5(pickle.dumps(self.__database)).hexdigest() 53 | 54 | @property 55 | def is_empty(self) -> bool: 56 | """Is the database empty?""" 57 | return not bool(sum((len(_) for _ in self.__database.values()))) 58 | 59 | def export_db(self, file: str, quiet: bool): 60 | """Export database to a file""" 61 | 62 | file += "" if file.endswith(".smog") else ".smog" 63 | 64 | with open(file, "wb") as output: 65 | pickle.dump(self.__database, output) # serialize the database 66 | 67 | self.last_sum_saved = self.md5sum 68 | 69 | if not quiet: 70 | Logger.success(f"Database exported to '{file}'.") 71 | 72 | def import_from_data(self, data: str): 73 | pass 74 | 75 | def export_to_data(self) -> str: 76 | """Export the database to a base64 string""" 77 | return base64.b64encode(pickle.dumps(self.__database)).decode("utf-8") 78 | 79 | def import_db(self, file: str): 80 | """Import database""" 81 | Logger.info(f"Importing database from '{file}'...") 82 | 83 | with open(file, "rb") as _input: 84 | self.__database = pickle.Unpickler(_input).load() 85 | 86 | Logger.success(f"Database imported from '{file}'.") 87 | 88 | @property 89 | def tables(self) -> List[DatabaseType]: 90 | """Get the list of tables""" 91 | return list(self.__database.keys()) 92 | 93 | @property 94 | def stats(self) -> Iterable[Tuple[DatabaseType, Union[float, int], int]]: 95 | """Get database stats""" 96 | total = sum(len(i) for i in self.__database.values()) 97 | 98 | return [ 99 | ( 100 | table, 101 | round(len(self.__database[table]) / total * 100), 102 | len(self.__database[table]), 103 | ) 104 | for table in self.__database.keys() 105 | ] 106 | 107 | def get_table_by_str(self, table: str) -> Optional[DatabaseType]: 108 | """Get table object with full name""" 109 | return next( 110 | ( 111 | _table 112 | for _table in self.tables 113 | if table in (_table.full_name, _table.name) 114 | ), 115 | None, 116 | ) 117 | 118 | def update_subdata(self, table: str, _id: int, key: str, value): 119 | """Update sub-data from a table""" 120 | if (_table := self.get_table_by_str(table)) is None: 121 | return Logger.error("Can't find the table.") 122 | 123 | if _id not in self.__database[_table]: 124 | return Logger.error(f"Can't find the data for id {_id}.") 125 | 126 | self.__database[_table][_id].sub_data[key] = value 127 | 128 | def delete_data(self, table: str, _id: int): 129 | """Delete data from a table""" 130 | if (_table := self.get_table_by_str(table)) is None: 131 | return Logger.error("Can't find the table.") 132 | 133 | if _id not in self.__database[_table]: 134 | return Logger.error("Can't find the data.") 135 | 136 | self.__database[_table].pop(_id) 137 | 138 | Logger.success(f"Deleted data from {table} where ID was equal to {_id}.") 139 | 140 | def get_id_by_value(self, value: str) -> int: 141 | """Get the id of a value""" 142 | 143 | def do_search(table: DatabaseType, value: str): 144 | items = list(map(lambda k: (k[0], k[1]), self.__database[table].items())) 145 | 146 | return next( 147 | (_id for _id, data in items if data.value == value), 148 | None, 149 | ) 150 | 151 | for table in self.tables: 152 | if (_id := do_search(table, value)) is not None: 153 | return _id 154 | 155 | return False 156 | 157 | def select_data( 158 | self, table: str, _id: Optional[int] = None 159 | ) -> Union[Literal[False], Dict[int, Type]]: 160 | """Select data from a table""" 161 | 162 | if (_table := self.get_table_by_str(table)) is None: 163 | return Logger.warn("Can't find the table.") 164 | 165 | return ( 166 | ( 167 | {_id: self.__database[_table][_id]} 168 | if _id is not None 169 | else self.__database[_table] 170 | ) 171 | if _table is not False 172 | else False 173 | ) 174 | 175 | def insert_data(self, data: Type) -> int | None: 176 | """Insert data into the table""" 177 | 178 | # data validation 179 | if data.validate() is False: 180 | return Logger.warn(f"Can't validate the data: '{data.value}'.") 181 | 182 | if (table := self.get_table_by_str(data.full_name)) is None: 183 | return Logger.warn("Can't find the table.") 184 | 185 | # don't add data if its already in the database 186 | for _, j in self.__database[table].items(): 187 | if j.value == data.value: 188 | return None 189 | 190 | # generate the ID 191 | _id = ( 192 | max(self.__database[table].keys()) + 1 193 | if len(self.__database[table]) > 0 194 | else 1 195 | ) 196 | 197 | self.__database[table][_id] = data # assign new data to the ID 198 | 199 | Logger.success(f"Added '{data.value}' to {table.full_name}.") 200 | 201 | return _id 202 | -------------------------------------------------------------------------------- /smog/database/types/__init__.py: -------------------------------------------------------------------------------- 1 | from .domain import Domain 2 | from .subdomain import Subdomain 3 | from .ip_address import IPAddress 4 | from .email import Email 5 | from .phone import Phone 6 | from .credentials import Credentials 7 | from .url import URL 8 | from .social import Social 9 | from .databaseserver import DatabaseServer 10 | from .port import Port 11 | -------------------------------------------------------------------------------- /smog/database/types/credentials.py: -------------------------------------------------------------------------------- 1 | from typing import Tuple, Union 2 | 3 | from smog.common.type import Type 4 | from smog.database.types.email import Email 5 | 6 | 7 | class Credentials(Type): 8 | """Credentials type""" 9 | 10 | name = "credential" 11 | full_name = "credentials" 12 | description = "Credentials" 13 | 14 | def __init__(self, value: Tuple[Union[Email, str], str]) -> None: 15 | super().__init__(value) 16 | 17 | def validate(self) -> bool: 18 | return True 19 | -------------------------------------------------------------------------------- /smog/database/types/databaseserver.py: -------------------------------------------------------------------------------- 1 | from typing import Literal, Tuple 2 | 3 | from smog.common.type import Type 4 | from smog.database.types.ip_address import IPAddress 5 | 6 | ValueType = Tuple[ 7 | IPAddress, int, str, str, str, Literal["mysql", "mssql", "mongodb", "postgresql"] 8 | ] 9 | 10 | 11 | class DatabaseServer(Type): 12 | """Database""" 13 | 14 | name = "database" 15 | full_name = "databases" 16 | description = "Database server" 17 | 18 | def __init__(self, value: ValueType) -> None: 19 | super().__init__(value) 20 | 21 | def validate(self) -> bool: 22 | return True 23 | -------------------------------------------------------------------------------- /smog/database/types/domain.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | from smog.common.type import Type 4 | 5 | 6 | class Domain(Type): 7 | """Domain database type""" 8 | 9 | name = "domain" 10 | full_name = "domains" 11 | description = "Domains" 12 | 13 | def validate(self) -> bool: 14 | return ( 15 | re.match(r"^[a-z0-9-]{1,63}(\.[a-z0-9-]{1,63})*$", self.value) is not None 16 | ) 17 | -------------------------------------------------------------------------------- /smog/database/types/email.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | from smog.common.type import Type 4 | 5 | 6 | class Email(Type): 7 | """Email type""" 8 | 9 | name = "email" 10 | full_name = "emails" 11 | description = "Email addresses" 12 | 13 | def validate(self) -> bool: 14 | return ( 15 | re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", self.value) 16 | is not None 17 | ) 18 | -------------------------------------------------------------------------------- /smog/database/types/ip_address.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | from smog.common.type import Type 4 | 5 | 6 | class IPAddress(Type): 7 | """IP address type""" 8 | 9 | name = "ip_addr" 10 | full_name = "ip_addrs" 11 | description = "IP addresses" 12 | 13 | def validate(self) -> bool: 14 | return ( 15 | re.match( 16 | r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", 17 | self.value, 18 | ) 19 | is not None 20 | ) 21 | -------------------------------------------------------------------------------- /smog/database/types/phone.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | from smog.common.type import Type 4 | 5 | 6 | class Phone(Type): 7 | """Phone number type""" 8 | 9 | name = "phone" 10 | full_name = "phones" 11 | description = "Phone numbers" 12 | 13 | def validate(self) -> bool: 14 | return ( 15 | re.match( 16 | r"^\+?[0-9]{1,3}\s?\(?[0-9]{3}\)?\s?[0-9]{3}\s?[0-9]{4}$", self.value 17 | ) 18 | is not None 19 | ) 20 | -------------------------------------------------------------------------------- /smog/database/types/port.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | from smog.common.type import Type 4 | 5 | 6 | class Port(Type): 7 | """Port type""" 8 | 9 | name = "port" 10 | full_name = "ports" 11 | description = "Ports" 12 | 13 | def validate(self) -> bool: 14 | return ( 15 | re.match( 16 | r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?):[0-9]{1,5}$", 17 | self.value, 18 | ) 19 | is not None 20 | ) 21 | -------------------------------------------------------------------------------- /smog/database/types/social.py: -------------------------------------------------------------------------------- 1 | from smog.common.type import Type 2 | 3 | TYPES = ("instagram.com", "facebook.com", "github.com") 4 | 5 | 6 | class Social(Type): 7 | """Social type""" 8 | 9 | name = "social" 10 | full_name = "socials" 11 | description = "Social networks" 12 | 13 | def validate(self) -> bool: 14 | return True 15 | -------------------------------------------------------------------------------- /smog/database/types/subdomain.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | from smog.common.type import Type 4 | 5 | 6 | class Subdomain(Type): 7 | """Subdomain database""" 8 | 9 | name = "subdomain" 10 | full_name = "subdomains" 11 | description = "Subdomains" 12 | 13 | def validate(self) -> bool: 14 | return ( 15 | re.match( 16 | r"^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$", 17 | self.value, 18 | ) 19 | is not None 20 | and self.value.count(".") >= 2 21 | ) 22 | -------------------------------------------------------------------------------- /smog/database/types/url.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | from smog.common.type import Type 4 | 5 | 6 | class URL(Type): 7 | """URL database type""" 8 | 9 | name = "url" 10 | full_name = "urls" 11 | description = "URLs" 12 | 13 | def validate(self) -> bool: 14 | return ( 15 | re.match( 16 | r"^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+" 17 | r"[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$", 18 | self.value, 19 | ) 20 | is not None 21 | ) 22 | -------------------------------------------------------------------------------- /smog/logger.py: -------------------------------------------------------------------------------- 1 | from rich.console import Console 2 | from typing import Literal 3 | 4 | from smog import VARIABLES 5 | 6 | console = Console() 7 | 8 | 9 | class Logger: 10 | """Logger class for Smog""" 11 | 12 | SUCCESS = "+" 13 | ERROR = "-" 14 | WARNING = "!" 15 | INFO = "*" 16 | 17 | @classmethod 18 | def __log(cls, message: str, prefix: str): 19 | """Log a message to the console""" 20 | console.print(f"[{prefix}] {message}") 21 | 22 | @classmethod 23 | def info(cls, message: str) -> Literal[True]: 24 | """Log an info message""" 25 | cls.__log(message, f"[bold cyan]{cls.INFO}[/bold cyan]") 26 | return True 27 | 28 | @classmethod 29 | def warn(cls, message: str) -> Literal[False]: 30 | """Log a warning message""" 31 | cls.__log(message, f"[bold yellow]{cls.WARNING}[/bold yellow]") 32 | return False 33 | 34 | @classmethod 35 | def error(cls, message: str) -> Literal[False]: 36 | """Log an error message""" 37 | cls.__log(message, f"[bold red]{cls.ERROR}[/bold red]") 38 | return False 39 | 40 | @classmethod 41 | def success(cls, message: str) -> Literal[True]: 42 | """Log a success message""" 43 | cls.__log(message, f"[bold green]{cls.SUCCESS}[/bold green]") 44 | return True 45 | -------------------------------------------------------------------------------- /smog/shell.py: -------------------------------------------------------------------------------- 1 | import time 2 | import random 3 | 4 | from os import system 5 | 6 | from prompt_toolkit import PromptSession 7 | from prompt_toolkit.history import InMemoryHistory 8 | from prompt_toolkit.completion import NestedCompleter 9 | 10 | from typing import Dict, FrozenSet, Union, Optional 11 | 12 | from smog import MODULES, COMMANDS, VARIABLES, database 13 | 14 | from smog.logger import Logger, console 15 | from smog.common.module import ModuleBase 16 | from smog.common.command import CommandBase 17 | from smog.utils.shell import parse_user_input, rich_to_ansi 18 | 19 | 20 | class Shell: 21 | """Shell class for Smog""" 22 | 23 | def __init__(self): 24 | self.selected_module = None 25 | self.project_name = None 26 | 27 | # list containing module objects 28 | self.modules = frozenset( 29 | module for module in MODULES if issubclass(module, ModuleBase) 30 | ) 31 | 32 | # list containing commands objets- 33 | self.commands = frozenset( 34 | command for command in COMMANDS if issubclass(command, CommandBase) 35 | ) 36 | 37 | # dictionnary to convert string to module object 38 | self.modules_map = {module.name.lower(): module for module in self.modules} 39 | 40 | # dictionnary to convert string to command object 41 | self.commands_map = {} 42 | 43 | for command in self.commands: 44 | self.commands_map[command.command.lower()] = command 45 | 46 | for alias in command.aliases: 47 | self.commands_map[alias.lower()] = command 48 | 49 | # setup completer 50 | json_data = {} 51 | 52 | for command in self.commands_map.values(): 53 | command = command((), self, console, database) 54 | command.init_arguments() 55 | 56 | json_data[command.command] = dict.fromkeys(command.parser.completions) 57 | 58 | # add from developer-provided arguments 59 | for argument in command._arguments: 60 | if argument not in json_data[command.command].keys(): 61 | json_data[command.command][argument] = None 62 | 63 | self.completer = NestedCompleter.from_nested_dict(json_data) 64 | 65 | # setup prompt 66 | self.prompt_session = PromptSession( 67 | completer=self.completer, 68 | complete_while_typing=True, 69 | wrap_lines=False, 70 | history=InMemoryHistory([command.command for command in self.commands]), 71 | ) 72 | 73 | @property 74 | def execution_time(self) -> int: 75 | """Get last command execution time""" 76 | return round(abs(self.start_time - self.end_time)) 77 | 78 | @property 79 | def prompt(self): 80 | """Get shell prompt""" 81 | prompt = "[bold white]smog[/]" 82 | 83 | if self.selected_module is not None: 84 | prompt += f"({self.selected_module.name})" 85 | 86 | if self.execution_time >= 2: 87 | prompt += f"(took {self.execution_time}s)" 88 | 89 | prompt += f" {VARIABLES['prompt-char'][0]} " 90 | 91 | return rich_to_ansi(prompt) 92 | 93 | def handle_command_line(self, user_input: str) -> None: 94 | """Handle user input""" 95 | if not user_input: 96 | return 97 | 98 | if user_input.startswith("!"): 99 | system(user_input[1:]) 100 | return 101 | 102 | command, arguments = parse_user_input(user_input) 103 | 104 | if (command_cls := self.commands_map.get(command, None)) is None: 105 | Logger.error(f"Unknown command: '{command}'.") 106 | return 107 | 108 | cmd_instance = command_cls(arguments, self, console, database) 109 | cmd_instance.init_arguments() 110 | 111 | if "-h" in arguments or "--help" in arguments: 112 | return cmd_instance.parser.print_help() 113 | 114 | try: 115 | cmd_instance.arguments = cmd_instance.parser.parse_args(arguments) 116 | cmd_instance.execute() 117 | except Exception as exc: 118 | if VARIABLES["exceptions_debug"][0] == "false": 119 | Logger.error(str(exc)) 120 | return 121 | 122 | return console.print_exception() 123 | 124 | def run(self) -> None: 125 | """Run the shell""" 126 | 127 | self.handle_command_line("clear -d") # clear screen 128 | self.start_time = time.time() 129 | 130 | while True: 131 | if self.project_name: 132 | self.handle_command_line(f"export -q {self.project_name}") 133 | 134 | self.end_time = time.time() 135 | user_input = self.prompt_session.prompt(self.prompt) 136 | self.start_time = time.time() 137 | 138 | self.handle_command_line(user_input) 139 | -------------------------------------------------------------------------------- /smog/utils/arguments.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | from rich.highlighter import RegexHighlighter 4 | from rich.console import Console 5 | from rich.markup import render 6 | from rich.theme import Theme 7 | from rich.panel import Panel 8 | from rich.text import Text 9 | from typing import Iterator, Tuple 10 | 11 | 12 | class Highlighter(RegexHighlighter): 13 | """Highlighter for arguments help""" 14 | 15 | base_style = "arguments." 16 | 17 | highlights = [ 18 | r"(?P[<\[]\w+[\]>])", 19 | r"(?P[\-]+[a-z]+)", 20 | r"(?P(options|positional arguments):)", 21 | ] 22 | 23 | 24 | theme = Theme( 25 | { 26 | "arguments.metavar": "bold white", 27 | "arguments.argument": "bold white", 28 | "arguments.usage": "white", 29 | "arguments.opt": "bold white", 30 | } 31 | ) 32 | 33 | console = Console(highlighter=Highlighter(), theme=theme) 34 | 35 | 36 | class ParserError(Exception): 37 | """Exception parser""" 38 | 39 | 40 | class HelpFormatter(argparse.HelpFormatter): 41 | """Custom help formatter""" 42 | 43 | def _metavar_formatter(self, action, default_metavar): 44 | result = action.metavar or ( 45 | "/".join(str(choice) for choice in action.choices) 46 | if action.choices 47 | else default_metavar 48 | ) 49 | 50 | def format(tuple_size): 51 | return result if isinstance(result, tuple) else (result,) * tuple_size 52 | 53 | return format 54 | 55 | 56 | class ArgumentParser(argparse.ArgumentParser): 57 | """Custom argument parser""" 58 | 59 | @property 60 | def completions(self) -> Iterator[str]: 61 | for action_x in self._action_groups: 62 | for action_y in action_x._group_actions: 63 | if action_y.choices is not None: 64 | yield from action_y.choices 65 | 66 | for action_z in action_y.option_strings: 67 | if action_z.startswith("-") is True: 68 | yield action_z 69 | 70 | def _get_formatter(self): 71 | """Return formatter""" 72 | return HelpFormatter( 73 | prog="", 74 | indent_increment=4, 75 | width=console.width, 76 | max_help_position=console.width, 77 | ) 78 | 79 | def format_help(self): 80 | formatter = self._get_formatter() 81 | 82 | for action_group in self._action_groups: 83 | if len(action_group._group_actions) == 1 and isinstance( 84 | action_group._group_actions[0], argparse._HelpAction 85 | ): 86 | continue 87 | 88 | formatter.start_section(action_group.title) 89 | formatter.add_text(action_group.description) 90 | formatter.add_arguments(action_group._group_actions) 91 | formatter.end_section() 92 | 93 | return formatter.format_help() 94 | 95 | def get_help(self) -> Tuple[Panel, Text]: 96 | """Display the help""" 97 | return ( 98 | Panel.fit(f"[bold white]{self.description}[/bold white]"), 99 | render(self.format_help()), 100 | ) 101 | 102 | def print_help(self): 103 | """Display the help""" 104 | console.print(Panel.fit(f"[bold white]{self.description}[/bold white]")) 105 | console.print(self.format_help(), highlight=True) 106 | 107 | def error(self, message): 108 | """Raise error message""" 109 | raise ParserError(message) 110 | -------------------------------------------------------------------------------- /smog/utils/shell.py: -------------------------------------------------------------------------------- 1 | from smog.logger import console 2 | 3 | from rich.text import Text 4 | from typing import List, Tuple 5 | from prompt_toolkit import ANSI 6 | 7 | 8 | def parse_user_input(user_input: str) -> Tuple[str, List[str]]: 9 | """Parse user input to command name and arguments""" 10 | command, *args = user_input.split() 11 | return command.lower(), args 12 | 13 | 14 | def rich_to_ansi(rich_text: str) -> ANSI: 15 | """Convert rich text to ANSI""" 16 | text, rendered = Text.from_markup(rich_text), "" 17 | 18 | for segment in text.render(console): 19 | if segment.style is None: 20 | continue 21 | 22 | style = segment.style.copy() 23 | 24 | style._color = segment.style.bgcolor 25 | style._bgcolor = style.color 26 | 27 | rendered += style.render(segment.text) 28 | 29 | return ANSI(rendered) 30 | --------------------------------------------------------------------------------