Converting binary sid's to a hex string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • LittlePython

    #1

    Converting binary sid's to a hex string

    I am trying to create a hexstring of a NT4 user account sid which I can in
    turn use to query an exchange 55 database. I believe I need to convert a
    binary sid to a hex string. ADsSID com object will do this for me however it
    is a little slow. Can anybody point me in the right direction to converting
    a PySID to a hexstring.
    Thx

    import win32netcon
    import win32net
    import win32security
    def report():
    resume = 0
    while 1:
    filter = win32netcon.FIL TER_NORMAL_ACCO UNT
    data, total, resume = win32net.NetUse rEnum('nt4pridc 1', 20, filter,
    resume)
    for user in data:
    MySid, string, int = win32security.L ookupAccountNam e('nt4pridc1',
    user['name'])
    sString = win32security.C onvertSidToStri ngSid(MySid)
    print MySid
    print sString
    if resume ==0:
    break

    report()
    ## sString prints = S-1-5-21-357043131-537017027-1947940980-1289
    ## MySid prints = PySID:S-1-5-21-357043131-537017027-1947940980-1289
    ## I need this , I believe this is a hex string of the SID
    ## 010500000000000 515000000BB0B48 15C33A022074381 B7409050000


  • Roger Upole

    #2
    Re: Converting binary sid's to a hex string

    You can use the binascii module to convert the raw
    bytes of the sid to hex.

    binascii.b2a_he x(buffer(MySid) )

    Roger

    "LittlePyth on" <LittlePython@l ost.com> wrote in message news:Y6Ehg.6441 $im3.3067@trndd c01...[color=blue]
    >I am trying to create a hexstring of a NT4 user account sid which I can in
    > turn use to query an exchange 55 database. I believe I need to convert a
    > binary sid to a hex string. ADsSID com object will do this for me however it
    > is a little slow. Can anybody point me in the right direction to converting
    > a PySID to a hexstring.
    > Thx
    >
    > import win32netcon
    > import win32net
    > import win32security
    > def report():
    > resume = 0
    > while 1:
    > filter = win32netcon.FIL TER_NORMAL_ACCO UNT
    > data, total, resume = win32net.NetUse rEnum('nt4pridc 1', 20, filter,
    > resume)
    > for user in data:
    > MySid, string, int = win32security.L ookupAccountNam e('nt4pridc1',
    > user['name'])
    > sString = win32security.C onvertSidToStri ngSid(MySid)
    > print MySid
    > print sString
    > if resume ==0:
    > break
    >
    > report()
    > ## sString prints = S-1-5-21-357043131-537017027-1947940980-1289
    > ## MySid prints = PySID:S-1-5-21-357043131-537017027-1947940980-1289
    > ## I need this , I believe this is a hex string of the SID
    > ## 010500000000000 515000000BB0B48 15C33A022074381 B7409050000
    >
    >[/color]




    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= East/West-Coast Server Farms - Total Privacy via Encryption =---

    Comment

    • LittlePython

      #3
      Re: Converting binary sid's to a hex string

      Thx Roger, I have been off line for a few days. I am sorry not to reply
      earlier. I will try this, but I am not sure what "buffer" does ( I am a
      newbie to python).


      "Roger Upole" <rupole@hotmail .com> wrote in message
      news:1149708725 _1865@sp6iad.su perfeed.net...[color=blue]
      > You can use the binascii module to convert the raw
      > bytes of the sid to hex.
      >
      > binascii.b2a_he x(buffer(MySid) )
      >
      > Roger
      >
      > "LittlePyth on" <LittlePython@l ost.com> wrote in message[/color]
      news:Y6Ehg.6441 $im3.3067@trndd c01...[color=blue][color=green]
      > >I am trying to create a hexstring of a NT4 user account sid which I can[/color][/color]
      in[color=blue][color=green]
      > > turn use to query an exchange 55 database. I believe I need to convert a
      > > binary sid to a hex string. ADsSID com object will do this for me[/color][/color]
      however it[color=blue][color=green]
      > > is a little slow. Can anybody point me in the right direction to[/color][/color]
      converting[color=blue][color=green]
      > > a PySID to a hexstring.
      > > Thx
      > >
      > > import win32netcon
      > > import win32net
      > > import win32security
      > > def report():
      > > resume = 0
      > > while 1:
      > > filter = win32netcon.FIL TER_NORMAL_ACCO UNT
      > > data, total, resume = win32net.NetUse rEnum('nt4pridc 1', 20,[/color][/color]
      filter,[color=blue][color=green]
      > > resume)
      > > for user in data:
      > > MySid, string, int =[/color][/color]
      win32security.L ookupAccountNam e('nt4pridc1',[color=blue][color=green]
      > > user['name'])
      > > sString = win32security.C onvertSidToStri ngSid(MySid)
      > > print MySid
      > > print sString
      > > if resume ==0:
      > > break
      > >
      > > report()
      > > ## sString prints = S-1-5-21-357043131-537017027-1947940980-1289
      > > ## MySid prints = PySID:S-1-5-21-357043131-537017027-1947940980-1289
      > > ## I need this , I believe this is a hex string of the SID
      > > ## 010500000000000 515000000BB0B48 15C33A022074381 B7409050000
      > >
      > >[/color]
      >
      >
      >
      >
      > ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet[/color]
      News==----[color=blue]
      > http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000[/color]
      Newsgroups[color=blue]
      > ---= East/West-Coast Server Farms - Total Privacy via Encryption =---[/color]


      Comment

      Working...