Jump to content
fedorffixxzz

[Py] Consola dinamica - pregatire argumente prin eval la func(*args)

Recommended Posts

Rezolvat cu o interfata mult mai curata, desi nu se scapa de tot de eval, merge. Design-ul pare in continuare a fi bun. Patch 1: [Diff] --- console.py.orig 2014-03-19 01:20:55.354217434 +0200 +++ console.py 2014-03- - Pastebin.com

--- console.py.orig	2014-03-19 01:20:55.354217434 +0200
+++ console.py 2014-03-22 12:00:35.252385497 +0200
@@ -16,6 +16,7 @@
import sys
import re
from md5 import md5
+ from collections import OrderedDict
from optparse import OptionParser, OptionGroup
except ImportError, IE:
print "\n[-] One or more modules is/are missing\n\n" \
@@ -363,7 +364,7 @@
else:
self._PLIST.pop(self.elem)

- def proxy_list(self, register=False, _PLIST=PROXYLIST, *proxies):
+ def proxy_list(self, register=False, _PLIST=PROXYLIST, **proxies):
"""Lists PROXYLIST"""
self.__cmd__ = "list"
self.__name__ = "%s_%s" % (self.__rootcmd__, self.__cmd__)
@@ -377,7 +378,7 @@
'execve': str(self.__execve__)+".%s" %
self.__name__,
'cmd': self.__name__.replace("_", " "),
- 'args': ['True', 'False', 'PROXYLIST', '%s']
+ 'args': [True, {'proxies': ['']}]
}
)
return True
@@ -387,30 +388,26 @@
self.count = 0
if len(self.proxies):
print
- DEBUG("Fetching proxy list for: %s" % self.proxies, 1, True)
+ DEBUG("Fetching proxy list for: %s" %
+ self.proxies[self.proxies.keys()[0]],
+ 1, True)

# then try to fetch each one
if len(self._PLIST.keys()) >= 1:
+ for val in self.proxies.values()[0]:
+ if val.strip() not in ['']:
found = False
- for self.proxy in self.proxies:
for k, v in self._PLIST.items():
- if str(self.proxy) == k or str(self.proxy) == v:
- try:
+ if k == val:
DEBUG('Found id: %s stored with value: %s' %
(k, v), 1)
- if not found:
found = True
- except:
- found = False
- try:
- DEBUG('Found: %s stored with id: %s'
- % (v, k), 1)
- if not found:
+ elif v == val:
+ DEBUG('Found: %s stored with id: %s' %
+ (v, k), 1)
found = True
- except:
- pass
- if found == False:
- DEBUG("Couldn't find %s" % self.proxy, 1)
+ if not found:
+ DEBUG("Couldn't find %s" % val, 1)
print
else:
DEBUG('List is empty\n', 3)
@@ -571,21 +568,22 @@
if MENU.get(index[0]):
try:
func = MENU[index[0]][index[1]]
- param = re.findall(r"'\s*([^']*?)\s*'",
- str(func['args'][1:]) % \
- ",".join(index[2:]).\
- strip(",")
- )
- DEBUG("Got plain param list -> %s" % param,
- reach=5)
- paraml = ""
- for x in param:
- paraml += x+","
- paraml = paraml.strip(",")
- DEBUG("Fetched parameter list -> %s" % paraml,
+
+ param = index[2:][0].split(",")
+ # FIX ME
+ param = [x for x in param \
+ if x.strip() not in ['', ' ']]
+ DEBUG("Fetched parameter list -> %s" % param,
reach=5)
+ # remove duplicates and keep ordered set
+ param = list(OrderedDict.fromkeys(param))
+
if func['args'][0]:
- eval(func['execve'])(*eval(paraml))
+ eval(func['execve'])(
+ **{func['args'][1].keys()[0]:
+ param
+ }
+ )
else:
DEBUG("This command does not take "
"any arguments\n", 1, force=True)

pentru cei ce nu stiu, in Linux pentru a aplica patch-ul, asumand ca script-ul este in pwd (console.py de mai jos reprezeinta cel din primul post; iar p1.patch este diff-ul salvat):

patch -p1 console.py < p1.patch

Acel FIXME trateaza parametrii ce au spatiu:

[>>>] proxy list 3,2,4,1,5,7,121,http://blah.org,451,http://test.com, bla
[DEBUG] Fetched parameter list -> ['3', '2', '4', '1', '5', '7', '121', 'http://blah.org', '451', 'http://test.com']

[INFO] Fetching proxy list for: ['3', '2', '4', '1', '5', '7', '121', 'http://blah.org', '451', 'http://test.com']
[INFO] Couldn't find 3
[INFO] Found id: 2 stored with value: http://blah.org
[INFO] Couldn't find 4
[INFO] Found id: 1 stored with value: http://test.com
[INFO] Couldn't find 5
[INFO] Couldn't find 7
[INFO] Couldn't find 121
[INFO] Found: http://blah.org stored with id: 2
[INFO] Couldn't find 451
[INFO] Found: http://test.com stored with id: 1

nu mai am timp dar sunt sigur ca este usor de rezolvat.

Sper sa ajute/inspire pe cineva design-ul asta.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...