Codebase list osrframework / debian/0.17.2-0kali1 osrframework / osrfconsole.py
debian/0.17.2-0kali1

Tree @debian/0.17.2-0kali1 (Download .tar.gz)

osrfconsole.py @debian/0.17.2-0kali1raw · history · blame

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
################################################################################
#
#    Copyright 2016-2017 FĂ©lix Brezo and Yaiza Rubio (i3visio, [email protected])
#
#    This program is part of OSRFramework. You can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################


__author__ = "Felix Brezo, Yaiza Rubio "
__copyright__ = "Copyright 2016-2017, i3visio"
__credits__ = ["Felix Brezo", "Yaiza Rubio"]
__license__ = "AGPLv3+"
__version__ = "v6.0"
__maintainer__ = "Felix Brezo, Yaiza Rubio"
__email__ = "[email protected]"


import argparse
import cmd as cmd
import json
import os
import sys

import osrframework.utils.configuration as configuration
import osrframework.utils.banner as banner
import osrframework.utils.general as general
import osrframework.utils.platform_selection as platform_selection
import osrframework.utils.regexp_selection as regexp_selection

import osrframework.domainfy as domainfy
import osrframework.entify as entify
import osrframework.mailfy as mailfy
import osrframework.phonefy as phonefy
import osrframework.searchfy as searchfy
import osrframework.usufy as usufy

UTILS = [
    "domainfy",
    "entify", #: regexp_selection.getAllRegexpNames(),
    "mailfy", # mailfy.EMAIL_DOMAINS,
    "phonefy",
    "searchfy",
    "usufy", # platform_selection.getAllPlatformNames("usufy"),
]

################################################################################
# Defining the abstract class of the utils that will be managed                #
################################################################################

class OSRFConsoleUtil(cmd.Cmd):
    """Simple class from which of a Metasploit-like interactive interface."""
    # Setting up the name of the module
    UNAME = "Abstract Util"

    intro = ""
    # Defining the prompt
    prompt = 'osrf (' + UNAME + ') > '
    # Defining the character to create hyphens
    ruler = '-'

    # Defining the configuration for this module
    CONFIG = {}
    CONFIG["OPTION"] = {
        "DESCRIPTION" : "An example of option.",
        "CURRENT_VALUE" : "Hello",
        "DEFAULT_VALUE" : "Hello",
        "REQUIRED" : False,
        "OPTIONS" : ["world", "people"]
    }
    CONFIG["OUTPUT"] = {
        "DESCRIPTION" : "The path to the output folder where the files will be created.",
        "CURRENT_VALUE" : "./",
        "DEFAULT_VALUE" : "./",
        "REQUIRED" : False,
        "OPTIONS" : []
    }
    CONFIG["EXTENSION"] = {
        "DESCRIPTION" : "The default extension of the files to be written.",
        "CURRENT_VALUE" : "csv",
        "DEFAULT_VALUE" : "csv",
        "REQUIRED" : False,
        "OPTIONS" : ['csv', 'xls', 'xlsx', 'json', 'gml']
    }

    def _checkIfRequiredAreSet(self):
        """Internal function to check if the required parameters have been set."""
        details = ""
        for key in self.CONFIG.keys():
            if self.CONFIG[key]["REQUIRED"] and self.CONFIG[key]["CURRENT_VALUE"] == None:
                return False
        return True

    def _getOptionsDescription(self):
        """Internal function to collect the description of each and every parameter"""
        details = ""
        for key in self.CONFIG.keys():
            details += "\t- " + key + ". " + self.CONFIG[key]["DESCRIPTION"] + "\n"
        return details

    def _getParams(self):
        """Function that creates the array with the params that will work with this function."""
        # Creating the parameters as if they were created using the command line
        params = ["-h"]
        return params

    def do_set(self, line):
        """Setting the variables defined in CONFIG. You can check their values at any time by typing 'show options'."""
        try:
            parameter, value = line.split(" ", 1)
            # Setting the parameter
            if parameter in self.CONFIG.keys():
                # Verifying if the parameter is in the options
                if len(self.CONFIG[parameter]["OPTIONS"]) > 0:
                    splittedValues = value.split(" ")

                    for s in splittedValues:
                        if s not in self.CONFIG[parameter]["OPTIONS"]:
                            raise Exception("ERROR: the value provided is not valid.")
                # Setting the value
                self.CONFIG[parameter]["CURRENT_VALUE"] = value
                print(general.info(parameter + "=" + str(value)))
            else:
                raise Exception("ERROR: parameter not valid.")
        except Exception as e:
            print(general.error("[!] ERROR: Not enough parameters provided. Usage: set OPTION VALUE."))
            print(general.error(str(e)))

    def complete_set(self, text, line, begidx, endidx):
        # First, we will try to get the available parameters
        if len(line.split(" ")) == 2:
            if not text:
                completions = self.CONFIG.keys()
            else:
                completions = [ f
                    for f in self.CONFIG.keys()
                    if f.startswith(text.upper())
                ]
        # We are setting the value
        elif len(line.split(" ")) >= 3:
            # First, we get the given parameter
            parameter = line.split(" ")[1]
            if not text:
                completions = self.CONFIG[parameter]["OPTIONS"]
            else:
                completions = [ f
                    for f in self.CONFIG[parameter]["OPTIONS"]
                    if f.startswith(text.lower())
                ]
        return completions

    def do_unset(self, line):
        """Unsetting the variables defined in CONFIG. You can check their values at any time by typing 'show options' and unsetting all the options at once by typing 'unset all'"."""
        try:
            parameter = line.split(" ")[0]
            # Getting the parameter
            if parameter in self.CONFIG.keys():
                # Unsetting the value
                self.CONFIG[parameter]["CURRENT_VALUE"] = self.CONFIG[parameter]["DEFAULT_VALUE"]
                print(general.info(parameter + " reseted to '" + str(self.CONFIG[parameter]["DEFAULT_VALUE"]) + "'."))
            elif parameter == "all":
                for p in self.CONFIG.keys():
                    # Unsetting all the values
                    self.CONFIG[p]["CURRENT_VALUE"] = self.CONFIG[p]["DEFAULT_VALUE"]
                print(general.info("All parameters reseted to their default values."))
            else:
                raise Exception("ERROR: parameter not valid.")
        except Exception as e:
            print(gemeral.error("[!] ERROR: Not enough parameters provided. Usage: unset OPTION"))
            print(general.error("Traceback: " + str(e)))

    def complete_unset(self, text, line, begidx, endidx):
        # First, we will try to get the available parameters
        unsettingOptions = ["all"] + self.CONFIG.keys()

        if len(line.split(" ")) == 2:
            if not text:
                completions = unsettingOptions
            else:
                completions = [ f
                    for f in unsettingOptions
                    if f.startswith(text.upper())
                ]
        return completions

    def do_run(self, line):
        """Command that send the order to the framework to launch the current utility."""
        if self._checkIfRequiredAreSet():
            print(general.info("Launching the util..."))
        else:
            print(general.error("There are required parameters which have not been set."))
            self.do_show("options")

    def do_show(self, line):
        """Showing the information about the module. The things to show are: 'options' and 'command'.
    - ' options' will show the current values of each and every parameter.
    - 'command' will show the command needed to launch the module as is using the cli applications."""
        if line.lower() == "options":
            print(general.info("Defining the different options for util " + self.UNAME + "..."))
            for key in self.CONFIG.keys():
                print(general.info("\t- " + (key + (" (*)." if self.CONFIG[key]["REQUIRED"] else ".") ).ljust(14) + "" + self.CONFIG[key]["DESCRIPTION"]))

            print(general.info("Showing the current state of the options for util " + self.UNAME + "..."))
            for key in self.CONFIG.keys():
                print(general.info("\t- " + (key + (" (*)" if self.CONFIG[key]["REQUIRED"] else "") + ": ").ljust(14) + ("" if self.CONFIG[key]["CURRENT_VALUE"] == None else str(self.CONFIG[key]["CURRENT_VALUE"]))))
        elif line.lower() == "command":
            print(general.info("Equivalent command to be launched to imitate the current configuration:\n\t$ ") + general.title(self.createCommandLine()) + "\n")

    def complete_show(self, text, line, begidx, endidx):
        # First, we will try to get the available parameters
        showOptions = ["options", "command"]

        if len(line.split(" ")) == 2:
            if not text:
                completions = showOptions
            else:
                completions = [ f
                    for f in showOptions
                    if f.startswith(text.lower())
                ]
        return completions

    def createCommandLine(self):
        """Method to build the commandline that should execute the same actions as defined in the console."""
        if self._checkIfRequiredAreSet():
            command = self.UNAME
            # Getting the params
            params = self._getParams()
            for p in params:
                command += " " +p
            # Returning the command
            return command
        else:
            return self.UNAME + " -h  # NOTE: all the required parameters are not set. Option '-h' is being shown."

    def do_info(self, line):
        """This command shows all the information available about the module."""
        print(general.info("Displaying module information."))
        self.do_show("options")
        self.do_show("command")

    def do_back(self, line):
        """
This command unloads the current util and returns back to the main console.
        """
        return True

    def do_exit(self, line):
        """This command will exit the osrfconsole normally."""
        print(general.info("Exiting the program..."))
        sys.exit()

"""
     _                       _        __
  __| | ___  _ __ ___   __ _(_)_ __  / _|_   _
 / _` |/ _ \| '_ ` _ \ / _` | | '_ \| |_| | | |
| (_| | (_) | | | | | | (_| | | | | |  _| |_| |
 \__,_|\___/|_| |_| |_|\__,_|_|_| |_|_|  \__, |
                                         |___/
"""


################################################################################
# Defining the class that will create the calls to the domainfy util.          #
################################################################################

class OSRFConsoleDomainfy(OSRFConsoleUtil):
    """Class that controls an interactive domainfy program."""
    # Setting up the name of the module
    UNAME = "domainfy.py"

    intro = ""
    # Defining the prompt
    prompt = general.emphasis('osrf (' + UNAME.split('.')[0] + ') > ')
    # Defining the character to create hyphens
    ruler = '-'

    DEFAULT_VALUES = configuration.returnListOfConfigurationValues("domainfy")

    # Defining the configuration for this module
    CONFIG = {}
    CONFIG["NICK"] = {
        "DESCRIPTION" : "Nick to be verified.",
        "CURRENT_VALUE" : None,
        "DEFAULT_VALUE" : None,
        "REQUIRED" : True,
        "OPTIONS" : []
    }
    CONFIG["TLD"] = {
        "DESCRIPTION" : "Types of TLD to be verified",
        "CURRENT_VALUE" : DEFAULT_VALUES["tlds"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["tlds"],
        "REQUIRED" : False,
        "OPTIONS" : domainfy.TLD.keys(),
    }
    CONFIG["THREADS"] = {
        "DESCRIPTION" : "Number of threads to use.",
        "CURRENT_VALUE" : DEFAULT_VALUES["threads"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["threads"],
        "REQUIRED" : False,
        "OPTIONS" : []
    }
    CONFIG["OUTPUT"] = {
        "DESCRIPTION" : "The path to the output folder where the files will be created.",
        "CURRENT_VALUE" : DEFAULT_VALUES["output_folder"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["output_folder"],
        "REQUIRED" : False,
        "OPTIONS" : []
    }
    CONFIG["EXTENSION"] = {
        "DESCRIPTION" : "The default extension of the files to be written.",
        "CURRENT_VALUE" : DEFAULT_VALUES["extension"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["extension"],
        "REQUIRED" : False,
        "OPTIONS" : ['csv', 'xls', 'xlsx', 'json', 'gml']
    }
    CONFIG["USER_DEFINED"] = {
        "DESCRIPTION" : "Other TLD to be verified. Note that it should start with a '.'.",
        "CURRENT_VALUE" : None,
        "DEFAULT_VALUE" : None,
        "REQUIRED" : False,
        "OPTIONS" : [],
    }

    def _getParams(self):
        """ Function that creates the array with the params that will work with this function"""
        # Creating the parameters as if they were created using the command line
        params = [
            "-n" ] + self.CONFIG["NICK"]["CURRENT_VALUE"].split() + [
            "-t" ] + self.CONFIG["TLD"]["CURRENT_VALUE"].split() + [
            "-T", str(self.CONFIG["THREADS"]["CURRENT_VALUE"]),
            "-o", self.CONFIG["OUTPUT"]["CURRENT_VALUE"],
            "-e" ] + self.CONFIG["EXTENSION"]["CURRENT_VALUE"].split()

        # Appending new tlds if provided
        if self.CONFIG["USER_DEFINED"]["CURRENT_VALUE"] != None:
            params += [ "-u", self.CONFIG["USER_DEFINED"]["CURRENT_VALUE"] ]
        return params

    def do_run(self, line):
        """Running the current application. This method should be redefined for each util."""
        print
        # Checking if all the required parameters have been set
        if self._checkIfRequiredAreSet():
            print(general.info("Collecting the options set by the user..."))
            # Getting the parser...
            parser = domainfy.getParser()

            # Generating the parameters
            params = self._getParams()

            args = parser.parse_args(params)

            print(general.info("Launching " + self.UNAME + " with the following parameters: ") + general.emphashis(str(params)))

            try:
                usufy.main(args)
            except Exception as e:
                print(gemeral.error("[!] ERROR. Something happenned when launching the utility. Type 'show options' to check the parameters. "))
                print(general.error("Traceback: " + str(e)))
        else:
            print(general.error("[!] ERROR. There are required parameters which have not been set."))
            self.do_show("options")
        print(general.success("Execution ended successfully."))

"""
================================================================================
            _   _  __
  ___ _ __ | |_(_)/ _|_   _
 / _ \ '_ \| __| | |_| | | |
|  __/ | | | |_| |  _| |_| |
 \___|_| |_|\__|_|_|  \__, |
                      |___/
================================================================================
"""

################################################################################
# Defining the class that will create the calls to the entify util.            #
################################################################################

class OSRFConsoleEntify(OSRFConsoleUtil):
    """Class that controls an interactive entify program."""
    # Setting up the name of the module
    UNAME = "entify.py"

    intro = ""
    # Defining the prompt
    prompt = 'osrf (' + UNAME.split('.')[0] + ') > '
    # Defining the character to create hyphens
    ruler = '-'

    DEFAULT_VALUES = configuration.returnListOfConfigurationValues("entify")

    # Defining the configuration for this module
    CONFIG = {}
    CONFIG["URL"] = {
        "DESCRIPTION" : "The URL to be checked.",
        "CURRENT_VALUE" : None,
        "DEFAULT_VALUE" : None,
        "REQUIRED" : True,
        "OPTIONS" : []
    }
    CONFIG["REGEXP"] = {
        "DESCRIPTION" : "The regular expressions to be checked.",
        "CURRENT_VALUE" : "all",
        "DEFAULT_VALUE" : "all",
        "REQUIRED" : False,
        "OPTIONS" : regexp_selection.getAllRegexpNames(),
    }
    CONFIG["OUTPUT"] = {
        "DESCRIPTION" : "The path to the output folder where the files will be created.",
        "CURRENT_VALUE" : DEFAULT_VALUES["output_folder"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["output_folder"],
        "REQUIRED" : False,
        "OPTIONS" : []
    }
    CONFIG["EXTENSION"] = {
        "DESCRIPTION" : "The default extension of the files to be written.",
        "CURRENT_VALUE" : DEFAULT_VALUES["extension"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["extension"],
        "REQUIRED" : False,
        "OPTIONS" : ['csv', 'xls', 'xlsx', 'json', 'gml']
    }

    def _getParams(self):
        """ Function that creates the array with the params that will work with this function"""
        # Creating the parameters as if they were created using the command line
        params = [
            "-u", self.CONFIG["URL"]["CURRENT_VALUE"],
            "-r" ] + self.CONFIG["REGEXP"]["CURRENT_VALUE"].split() + [
            "-o", self.CONFIG["OUTPUT"]["CURRENT_VALUE"],
            "-e" ] + self.CONFIG["EXTENSION"]["CURRENT_VALUE"].split()

        return params

    def do_run(self, line):
        """Running the current application. This method should be redefined for each util."""
        print
        # Checking if all the required parameters have been set
        if self._checkIfRequiredAreSet():
            print(general.info("Collecting the options set by the user..."))
            # Getting the parser...
            parser = entify.getParser()

            # Generating the parameters
            params = self._getParams()

            args = parser.parse_args(params)

            print(general.info("Launching " + self.UNAME + " with the following parameters: ") + general.emphashis(str(params)))

            try:
                usufy.main(args)
            except Exception as e:
                print(gemeral.error("[!] ERROR. Something happened when launching the utility. Type 'show options' to check the parameters. "))
                print(general.error("Traceback: " + str(e)))
        else:
            print(general.error("[!] ERROR. There are required parameters which have not been set."))
            self.do_show("options")
        print(general.success("Execution ended successfully."))

"""
================================================================================
                 _ _  __
 _ __ ___   __ _(_) |/ _|_   _
| '_ ` _ \ / _` | | | |_| | | |
| | | | | | (_| | | |  _| |_| |
|_| |_| |_|\__,_|_|_|_|  \__, |
                         |___/
================================================================================
"""

################################################################################
# Defining the class that will create the calls to the mailfy util.             #
################################################################################

class OSRFConsoleMailfy(OSRFConsoleUtil):
    """Class that controls an interactive mailfy program."""
    # Setting up the name of the module
    UNAME = "mailfy.py"

    intro = ""
    # Defining the prompt
    prompt = 'osrf (' + UNAME.split('.')[0] + ') > '
    # Defining the character to create hyphens
    ruler = '-'

    DEFAULT_VALUES = configuration.returnListOfConfigurationValues("mailfy")

    # Defining the configuration for this module
    CONFIG = {}
    CONFIG["NICK"] = {
        "DESCRIPTION" : "Alias to be verified.",
        "CURRENT_VALUE" : None,
        "DEFAULT_VALUE" : None,
        "REQUIRED" : True,
        "OPTIONS" : []
    }
    CONFIG["PLATFORMS"] = {
        "DESCRIPTION" : "Platforms to be checked.",
        "CURRENT_VALUE" : DEFAULT_VALUES["domains"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["domains"],
        "REQUIRED" : False,
        "OPTIONS" : mailfy.EMAIL_DOMAINS,
    }
    CONFIG["THREADS"] = {
        "DESCRIPTION" : "Number of threads to use.",
        "CURRENT_VALUE" : DEFAULT_VALUES["threads"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["threads"],
        "REQUIRED" : False,
        "OPTIONS" : []
    }
    CONFIG["OUTPUT"] = {
        "DESCRIPTION" : "The path to the output folder where the files will be created.",
        "CURRENT_VALUE" : DEFAULT_VALUES["output_folder"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["output_folder"],
        "REQUIRED" : False,
        "OPTIONS" : []
    }
    CONFIG["EXTENSION"] = {
        "DESCRIPTION" : "The default extension of the files to be written.",
        "CURRENT_VALUE" : DEFAULT_VALUES["extension"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["extension"],
        "REQUIRED" : False,
        "OPTIONS" : ['csv', 'xls', 'xlsx', 'json', 'gml']
    }

    def _getParams(self):
        """ Function that creates the array with the params that will work with this function"""
        # Creating the parameters as if they were created using the command line
        params = [
            "-n" ] + self.CONFIG["NICK"]["CURRENT_VALUE"].split() + [
            "-p" ] + self.CONFIG["PLATFORMS"]["CURRENT_VALUE"].split() + [
            "-T", str(self.CONFIG["THREADS"]["CURRENT_VALUE"]),
            "-o", self.CONFIG["OUTPUT"]["CURRENT_VALUE"],
            "-e" ] + self.CONFIG["EXTENSION"]["CURRENT_VALUE"].split()

        return params

    def do_run(self, line):
        """Running the current application. This method should be redefined for each util."""
        print
        # Checking if all the required parameters have been set
        if self._checkIfRequiredAreSet():
            print(general.info("Collecting the options set by the user..."))
            # Getting the parser...
            parser = mailfy.getParser()

            # Generating the parameters
            params = self._getParams()

            args = parser.parse_args(params)

            print(general.info("Launching " + self.UNAME + " with the following parameters: ") + general.emphashis(str(params)))

            try:
                usufy.main(args)
            except Exception as e:
                print(gemeral.error("[!] ERROR. Something happenned when launching the utility. Type 'show options' to check the parameters. "))
                print(general.error("Traceback: " + str(e)))
        else:
            print(general.error("[!] ERROR. There are required parameters which have not been set."))
            self.do_show("options")
        print(general.success("Execution ended successfully."))

"""
================================================================================
       _                       __
 _ __ | |__   ___  _ __   ___ / _|_   _
| '_ \| '_ \ / _ \| '_ \ / _ \ |_| | | |
| |_) | | | | (_) | | | |  __/  _| |_| |
| .__/|_| |_|\___/|_| |_|\___|_|  \__, |
|_|                               |___/
================================================================================
"""

################################################################################
# Defining the class that will create the calls to the phonefy util.          #
################################################################################

class OSRFConsolePhonefy(OSRFConsoleUtil):
    """Class that controls an interactive phonefy program."""
    # Setting up the name of the module
    UNAME = "phonefy.py"

    intro = ""
    # Defining the prompt
    prompt = 'osrf (' + UNAME.split('.')[0] + ') > '
    # Defining the character to create hyphens
    ruler = '-'

    DEFAULT_VALUES = configuration.returnListOfConfigurationValues("phonefy")

    # Defining the configuration for this module
    CONFIG = {}
    CONFIG["NUMBER"] = {
        "DESCRIPTION" : "Numbers to be verified.",
        "CURRENT_VALUE" : None,
        "DEFAULT_VALUE" : None,
        "REQUIRED" : True,
        "OPTIONS" : []
    }
    CONFIG["PLATFORMS"] = {
        "DESCRIPTION" : "Platforms to be checked.",
        "CURRENT_VALUE" : DEFAULT_VALUES["platforms"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["platforms"],
        "REQUIRED" : False,
        "OPTIONS" : platform_selection.getAllPlatformNames("phonefy"),
    }
    CONFIG["OUTPUT"] = {
        "DESCRIPTION" : "The path to the output folder where the files will be created.",
        "CURRENT_VALUE" : DEFAULT_VALUES["output_folder"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["output_folder"],
        "REQUIRED" : False,
        "OPTIONS" : []
    }
    CONFIG["EXTENSION"] = {
        "DESCRIPTION" : "The default extension of the files to be written.",
        "CURRENT_VALUE" : DEFAULT_VALUES["extension"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["extension"],
        "REQUIRED" : False,
        "OPTIONS" : ['csv', 'xls', 'xlsx', 'json', 'gml']
    }

    def _getParams(self):
        """ Function that creates the array with the params that will work with this function"""
        # Creating the parameters as if they were created using the command line
        params = [
            "-n" ] + self.CONFIG["NICK"]["CURRENT_VALUE"].split() + [
            "-p" ] + self.CONFIG["PLATFORMS"]["CURRENT_VALUE"].split() + [
            "-o", self.CONFIG["OUTPUT"]["CURRENT_VALUE"],
            "-e" ] + self.CONFIG["EXTENSION"]["CURRENT_VALUE"].split()

        return params

    def do_run(self, line):
        """
Running the current application. This method should be redefined for each util.
        """
        print
        # Checking if all the required parameters have been set
        if self._checkIfRequiredAreSet():
            print(general.info("Collecting the options set by the user..."))
            # Getting the parser...
            parser = phonefy.getParser()

            # Generating the parameters
            params = self._getParams()

            args = parser.parse_args(params)

            print(general.info("Launching " + self.UNAME + " with the following parameters: ") + general.emphashis(str(params)))

            try:
                usufy.main(args)
            except Exception as e:
                print(gemeral.error("[!] ERROR. Something happenned when launching the utility. Type 'show options' to check the parameters. "))
                print(general.error("Traceback: " + str(e)))
        else:
            print(general.error("[!] ERROR. There are required parameters which have not been set."))
            self.do_show("options")
        print(general.success("Execution ended successfully."))

"""
================================================================================
                         _      __
 ___  ___  __ _ _ __ ___| |__  / _|_   _
/ __|/ _ \/ _` | '__/ __| '_ \| |_| | | |
\__ \  __/ (_| | | | (__| | | |  _| |_| |
|___/\___|\__,_|_|  \___|_| |_|_|  \__, |
                                   |___/
================================================================================
"""

################################################################################
# Defining the class that will create the calls to the searchfy util.          #
################################################################################

class OSRFConsoleSearchfy(OSRFConsoleUtil):
    """Class that controls an interactive searchfy program"""
    # Setting up the name of the module
    UNAME = "searchfy.py"

    intro = ""
    # Defining the prompt
    prompt = 'osrf (' + UNAME.split('.')[0] + ') > '
    # Defining the character to create hyphens
    ruler = '-'

    DEFAULT_VALUES = configuration.returnListOfConfigurationValues("searchfy")

    # Defining the configuration for this module
    CONFIG = {}
    CONFIG["QUERY"] = {
        "DESCRIPTION" : "Query to be verified. Escape \" and \'.",
        "CURRENT_VALUE" : None,
        "DEFAULT_VALUE" : None,
        "REQUIRED" : True,
        "OPTIONS" : []
    }
    CONFIG["PLATFORMS"] = {
        "DESCRIPTION" : "Platforms to be checked.",
        "CURRENT_VALUE" : DEFAULT_VALUES["platforms"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["platforms"],
        "REQUIRED" : False,
        "OPTIONS" : platform_selection.getAllPlatformNames("searchfy"),
    }
    CONFIG["OUTPUT"] = {
        "DESCRIPTION" : "The path to the output folder where the files will be created.",
        "CURRENT_VALUE" : DEFAULT_VALUES["output_folder"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["output_folder"],
        "REQUIRED" : False,
        "OPTIONS" : []
    }
    CONFIG["EXTENSION"] = {
        "DESCRIPTION" : "The default extension of the files to be written.",
        "CURRENT_VALUE" : DEFAULT_VALUES["extension"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["extension"],
        "REQUIRED" : False,
        "OPTIONS" : ['csv', 'xls', 'xlsx', 'json', 'gml']
    }

    def _getParams(self):
        """ Function that creates the array with the params that will work with this function"""
        # Creating the parameters as if they were created using the command line
        params = [
            "-q" ] + self.CONFIG["QUERY"]["CURRENT_VALUE"].split() + [
            "-p" ] + self.CONFIG["PLATFORMS"]["CURRENT_VALUE"].split() + [
            "-o", self.CONFIG["OUTPUT"]["CURRENT_VALUE"],
            "-e" ] + self.CONFIG["EXTENSION"]["CURRENT_VALUE"].split()

        return params

    def do_run(self, line):
        """Running the current application. This method should be redefined for each util.
        """
        print
        # Checking if all the required parameters have been set
        if self._checkIfRequiredAreSet():
            print(general.info("Collecting the options set by the user..."))
            # Getting the parser...
            parser = searchfy.getParser()

            # Generating the parameters
            params = self._getParams()

            args = parser.parse_args(params)

            print(general.info("Launching " + self.UNAME + " with the following parameters: ") + general.emphashis(str(params)))

            try:
                usufy.main(args)
            except Exception as e:
                print(gemeral.error("[!] ERROR. Something happenned when launching the utility. Type 'show options' to check the parameters. "))
                print(general.error("Traceback: " + str(e)))
        else:
            print(general.error("[!] ERROR. There are required parameters which have not been set."))
            self.do_show("options")
        print(general.success("Execution ended successfully."))

"""
================================================================================
                      __
     _   _ ___ _   _ / _|_   _
    | | | / __| | | | |_| | | |
    | |_| \__ \ |_| |  _| |_| |
     \__,_|___/\__,_|_|  \__, |
                         |___/
================================================================================
"""

################################################################################
# Defining the class that will create the calls to the usufy util.             #
################################################################################

class OSRFConsoleUsufy(OSRFConsoleUtil):
    """Class that controls an interactive usufy program"""
    # Setting up the name of the module
    UNAME = "usufy.py"

    intro = ""
    # Defining the prompt
    prompt = general.emphasis('osrf (' + UNAME.split('.')[0] + ') > ')
    # Defining the character to create hyphens
    ruler = '-'

    DEFAULT_VALUES = configuration.returnListOfConfigurationValues("usufy")

    # Defining the configuration for this module
    CONFIG = {}
    CONFIG["NICK"] = {
        "DESCRIPTION" : "Alias to be verified.",
        "CURRENT_VALUE" : None,
        "DEFAULT_VALUE" : None,
        "REQUIRED" : True,
        "OPTIONS" : []
    }
    CONFIG["PLATFORMS"] = {
        "DESCRIPTION" : "Platforms to be checked.",
        "CURRENT_VALUE" : DEFAULT_VALUES["platforms"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["platforms"],
        "REQUIRED" : False,
        "OPTIONS" : platform_selection.getAllPlatformNames("usufy"),
    }
    CONFIG["THREADS"] = {
        "DESCRIPTION" : "Number of threads to use.",
        "CURRENT_VALUE" : DEFAULT_VALUES["threads"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["threads"],
        "REQUIRED" : False,
        "OPTIONS" : []
    }
    CONFIG["OUTPUT"] = {
        "DESCRIPTION" : "The path to the output folder where the files will be created.",
        "CURRENT_VALUE" : DEFAULT_VALUES["output_folder"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["output_folder"],
        "REQUIRED" : False,
        "OPTIONS" : []
    }
    CONFIG["EXTENSION"] = {
        "DESCRIPTION" : "The default extension of the files to be written.",
        "CURRENT_VALUE" : DEFAULT_VALUES["extension"],
        "DEFAULT_VALUE" : DEFAULT_VALUES["extension"],
        "REQUIRED" : False,
        "OPTIONS" : ['csv', 'xls', 'xlsx', 'json', 'gml']
    }

    def _getParams(self):
        """Function that creates the array with the params that will work with this function."""
        # Creating the parameters as if they were created using the command line
        params = [
            "-n" ] + self.CONFIG["NICK"]["CURRENT_VALUE"].split() + [
            "-p" ]  +  self.CONFIG["PLATFORMS"]["CURRENT_VALUE"].split() + [
            "-T", str(self.CONFIG["THREADS"]["CURRENT_VALUE"]),
            "-o", self.CONFIG["OUTPUT"]["CURRENT_VALUE"],
            "-e" ] + self.CONFIG["EXTENSION"]["CURRENT_VALUE"].split()

        return params

    def do_run(self, line):
        """Running the current application. This method should be redefined for each util."""
        print
        # Checking if all the required parameters have been set
        if self._checkIfRequiredAreSet():
            print(general.info("Collecting the options set by the user..."))
            # Getting the parser...
            parser = usufy.getParser()

            # Generating the parameters
            params = self._getParams()

            args = parser.parse_args(params)

            print(general.info("Launching " + self.UNAME + " with the following parameters: ") + general.emphashis(str(params)))

            try:
                usufy.main(args)
            except Exception as e:
                print(gemeral.error("[!] ERROR. Something happenned when launching the utility. Type 'show options' to check the parameters. "))
                print(general.error("Traceback: " + str(e)))
        else:
            print(general.error("[!] ERROR. There are required parameters which have not been set."))
            self.do_show("options")
        print(general.success("Execution ended successfully."))


"""
================================================================================
                     __                           _
      ___  ___ _ __ / _| ___ ___  _ __  ___  ___ | | ___
     / _ \/ __| '__| |_ / __/ _ \| '_ \/ __|/ _ \| |/ _ \
    | (_) \__ \ |  |  _| (_| (_) | | | \__ \ (_) | |  __/
     \___/|___/_|  |_|  \___\___/|_| |_|___/\___/|_|\___|

================================================================================
"""
################################################################################
# Main osrfconsole wrapper. It will control the rest of the utils.             #
################################################################################

class OSRFConsoleMain(cmd.Cmd):
    """
    OSRFramework console application to control the different framework utils.

    Type 'help' to find the commands.
    """

    DISCLAIMER = '''\tOSRFConsole ''' + __version__ + ''' - Copyright (C) F. Brezo and Y. Rubio (i3visio) 2016-2017

This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain conditions.  For additional info, visit to <http://www.gnu.org/licenses/gpl-3.0.txt>.'''

    intro = banner.text + "\n" + DISCLAIMER

    info  = "\n    General information"
    info += "\n    ==================="
    info += "\n    OSRFramework stands for Open Sources Research Framework. It includes a set of tools that help the analyst in the task of user profiling making use of different OSINT tools. To get additional information about the available commands type 'help'."
    info += "\n"
    info += "\n    Modules available:"
    info += "\n    ------------------"
    info += "\n\t- usufy --> the Jewel of the Chrown. A tool that verifies if a username exists in " + str(len(platform_selection.getAllPlatformNames("usufy")))  + " platforms."
    info += "\n\t- mailfy --> a tool to check if a username has been registered in up to " + str(len(mailfy.EMAIL_DOMAINS )) + " email providers."
    info += "\n\t- searchfy --> a tool to look for profiles using full names and other info in " + str(len(platform_selection.getAllPlatformNames("searchfy")))  + " platforms."
    info += "\n\t- domainfy --> a tool to check the existence of a given domain in up to " + str(domainfy.getNumberTLD()) + " different TLD."
    info += "\n\t- phonefy --> a tool that checks if a phone number has been linked to spam practices in " + str(len(platform_selection.getAllPlatformNames("phonefy")))  + " platforms."
    info += "\n\t- entify --> a util to look for regular expressions using " + str(len(regexp_selection.getAllRegexpNames())) + " patterns."
    info += "\n"

    # Appending the self.info data to the headers...
    intro += info

    # Defining the prompt
    prompt = general.emphasis('osrf > ')

    ruler = '='

    def do_info(self, line):
        """
        Command that shows again the general information about the application.
        """
        configInfo =  "\n    Additional configuration files:"
        configInfo += "\n    -------------------------------"
        configInfo += "\n    You will be able to find more configuration options in the following files in your system. The relevant paths are the ones that follows:"

        # Get the configuration folders in each system
        paths = configuration.getConfigPath()

        configInfo += "\n\t- '" + os.path.join(paths["appPath"], "accounts.cfg") + "' -> Configuration details about the login credentials already configured in the framework."
        configInfo += "\n\t- '" + os.path.join(paths["appPath"], "api_keys.cfg") + "' -> Configuration details about the API credentials already configured."
        configInfo += "\n\t- '" + os.path.join(paths["appPath"], "browser.cfg") + "' -> Connection configuration about how the browsers will be connected."
        configInfo += "\n\t- '" + os.path.join(paths["appPath"], "general.cfg") + "' -> General configuration of the different utils containing the default options."
        configInfo += "\n\t- '" + paths["appPathDefaults"] + "/' -> Directory containing default files as a backup."
        configInfo += "\n\t- '" + paths["appPathPlugins"] + "/' -> Directory containing the details of the user defined plugins."
        configInfo += "\n\t- '" + paths["appPathPatterns"] + "/' -> Directory containing the user-defined patterns for entify.py."
        configInfo += "\n\t- '" + paths["appPathWrappers"] + "/' -> Directory containing the user-defined wrappers for usufy, searchfy and phonefy platforms."
        configInfo += "\n"
        print(general.title(self.info) + general.info(configInfo))

    def do_use(self, line):
        """
        This command will define which of the framework's utilities will be loaded.

        The available options are the following:
            - domainfy
            - entify
            - mailfy
            - phonefy
            - searchfy
            - usufy
        For example, type 'use usufy' to load the usufy util. You can always use
        the <TAB> to be helped using the autocomplete options.
        """
        if line not in UTILS:
            print(general.warning("[!] Util is not correct. Try 'help use' to check the available options."))
            return False
        elif line == "domainfy":
            OSRFConsoleDomainfy().cmdloop()
        elif line == "entify":
            OSRFConsoleEntify().cmdloop()
        elif line == "mailfy":
            OSRFConsoleMailfy().cmdloop()
        elif line == "phonefy":
            OSRFConsolePhonefy().cmdloop()
        elif line == "searchfy":
            OSRFConsoleSearchfy().cmdloop()
        elif line == "usufy":
            OSRFConsoleUsufy().cmdloop()
        else:
            print(general.warning("[!] Not implemented yet. Try 'help use' to check the available options."))

    def complete_use(self, text, line, begidx, endidx):
        if not text:
            completions = UTILS
        else:
            completions = [ f
                for f in UTILS
                if f.startswith(text.lower())
            ]
        return completions

    def do_exit(self, line):
        """
        This command will exit osrfconsole normally.
        """
        print(info("Exiting..."))
        sys.exit()


if __name__ == '__main__':
    OSRFConsoleMain().cmdloop()