Skip to content

Instantly share code, notes, and snippets.

@lovemyliwu
Last active October 22, 2022 09:26
Show Gist options
  • Select an option

  • Save lovemyliwu/48eeaf566978ec24843b743877df0021 to your computer and use it in GitHub Desktop.

Select an option

Save lovemyliwu/48eeaf566978ec24843b743877df0021 to your computer and use it in GitHub Desktop.

Revisions

  1. lovemyliwu revised this gist Oct 22, 2022. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions cli.py
    Original file line number Diff line number Diff line change
    @@ -6,13 +6,13 @@
    def main(argv):
    parser = OptionParser()
    parser.add_option("-u", "--username",
    help="Username that will be used for authentication")
    help="windows username that will be used for authentication")
    parser.add_option("-p", "--password",
    help="Password that will be used for authentication")
    help="windows password that will be used for authentication")
    parser.add_option("-s", "--system-name",
    help="windows domain name")
    help="smb server machine name")
    parser.add_option("-d", "--domain",
    help="Domain name that will be used for authentication")
    help="windows domain name that will be used for authentication")
    (options, args) = parser.parse_args()

    system_name = options.system_name
  2. lovemyliwu revised this gist Oct 22, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cli.py
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ def main(argv):
    parser.add_option("-p", "--password",
    help="Password that will be used for authentication")
    parser.add_option("-s", "--system-name",
    help="Read systems list from file")
    help="windows domain name")
    parser.add_option("-d", "--domain",
    help="Domain name that will be used for authentication")
    (options, args) = parser.parse_args()
  3. lovemyliwu created this gist Oct 22, 2022.
    59 changes: 59 additions & 0 deletions cli.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    import sys
    from optparse import OptionParser
    from smb.SMBConnection import SMBConnection


    def main(argv):
    parser = OptionParser()
    parser.add_option("-u", "--username",
    help="Username that will be used for authentication")
    parser.add_option("-p", "--password",
    help="Password that will be used for authentication")
    parser.add_option("-s", "--system-name",
    help="Read systems list from file")
    parser.add_option("-d", "--domain",
    help="Domain name that will be used for authentication")
    (options, args) = parser.parse_args()

    system_name = options.system_name
    try:
    print('### Analyzing system: ' + system_name)
    # parameterize an smb connection with a system
    conn = SMBConnection(options.username,
    options.password,
    'enumerator',
    options.system_name,
    options.domain,
    use_ntlm_v2=True,
    sign_options=SMBConnection.SIGN_WHEN_SUPPORTED,
    is_direct_tcp=True)

    # establish the actual connection
    connected = conn.connect(system_name,445)

    try:
    Response = conn.listShares(timeout=30) # obtain a list of shares
    print('Shares on: ' + system_name)
    for i in range(len(Response)): # iterate through the list of shares
    print(" Share[",i,"] =", Response[i].name)

    try:
    # list the files on each share (recursivity?)
    Response2 = conn.listPath(Response[i].name,'/',timeout=30)
    print(' Files on: ' + system_name + '/' + " Share[",i,"] =",
    Response[i].name)
    for i in range(len(Response2)):
    print(" File[",i,"] =", Response2[i].filename)

    except:
    print('### can not access the resource')

    except Exception as error:
    print('### can not list shares')

    except:
    print('### can not access the system')


    if __name__ == "__main__":
    main(sys.argv[1:])