readlines and break apart based on letters

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

    #1

    readlines and break apart based on letters

    Hi,

    While trying to better understand security descriptors on Windows. I've
    been examining text-based security descriptors. I have the security
    descriptors on individual lines stored in a text file. I want to break
    these lines apart based on owner, group, dacl and sacl. These areas are
    demarcated by O: G: D: and S:

    There are no spaces in the lines. How can I read each line so that each
    area is broken out? I'd like output like this:

    O: details
    G: details or NONE
    D: details or NONE
    S: details or NONE

    Here is an example SD:
    O:owner_sidG:gr oup_sidD:dacl_f lags(string_ace 1)(string_ace2) ...(string_acen )S:sacl_flags(s tring_ace1)(str ing_ace2)...(st ring_acen)

    I want to read this and break it apart like this:
    O:owner_sid
    G:group_sid
    D:dacl_flags(st ring_ace1)(stri ng_ace2)...(str ing_acen)
    S:sacl_flags(st ring_ace1)(stri ng_ace2)...(str ing_acen)

    Any tips?
    Brad

  • rtilley

    #2
    Re: readlines and break apart based on letters

    I got this to work... just FYI:

    s =
    'O:owner_sidG:g roup_sidD:dacl_ flags(string_ac e1)(string_ace2 )...(string_ace n)S:sacl_flags( string_ace1)(st ring_ace2)...(s tring_acen)'

    SD = {}

    S = str.split(s, 'S:')
    SD['S_ACL'] = S[1]
    D = str.split(S[0], 'D:')
    SD['D_ACL'] = D[1]
    G = str.split(D[0], 'G:')
    SD['G_SID'] = G[1]
    O = str.split(G[0], 'O:')
    SD['O_SID'] = O[1]

    for k,v in SD.iteritems():
    print k,v

    Comment

    • Kent Johnson

      #3
      Re: readlines and break apart based on letters

      rtilley wrote:[color=blue]
      > Hi,
      >
      > While trying to better understand security descriptors on Windows. I've
      > been examining text-based security descriptors. I have the security
      > descriptors on individual lines stored in a text file. I want to break
      > these lines apart based on owner, group, dacl and sacl. These areas are
      > demarcated by O: G: D: and S:
      >
      > There are no spaces in the lines. How can I read each line so that each
      > area is broken out? I'd like output like this:
      >
      > O: details
      > G: details or NONE
      > D: details or NONE
      > S: details or NONE
      >
      > Here is an example SD:
      > O:owner_sidG:gr oup_sidD:dacl_f lags(string_ace 1)(string_ace2) ...(string_acen )S:sacl_flags(s tring_ace1)(str ing_ace2)...(st ring_acen)[/color]

      It's a pretty simple regex:[color=blue][color=green][color=darkred]
      >>> import re
      >>>[/color][/color][/color]
      s='O:owner_sidG :group_sidD:dac l_flags(string_ ace1)(string_ac e2)...(string_a cen)S:sacl_flag s(string_ace1)( string_ace2)... (string_acen)'[color=blue][color=green][color=darkred]
      >>>
      >>> m=re.search(r'O :(.*?)G:(.*?)D: (.*?)S:(.*)', s)
      >>> m.group(1,2,3,4 )[/color][/color][/color]
      ('owner_sid', 'group_sid',
      'dacl_flags(str ing_ace1)(strin g_ace2)...(stri ng_acen)',
      'sacl_flags(str ing_ace1)(strin g_ace2)...(stri ng_acen)')

      Comment

      Working...