Giter Site home page Giter Site logo

Comments (6)

SteveMcGrath avatar SteveMcGrath commented on July 17, 2024

I cannot replicate this, can you give further details? maybe some example code?

from pysecuritycenter.

vitalisec avatar vitalisec commented on July 17, 2024

Here's my code.

#!/usr/bin/env/python

from boto import ec2
import getpass
from securitycenter import SecurityCenter5

def get_AWS_instances(AWS_Access_Key,AWS_Secret_Key):

    AWS_ACCESS_KEY_ID=AWS_Access_Key
    AWS_SECRET_ACCESS_KEY=AWS_Secret_Key
    ip_list = []
    noscan = 0

    ec2conn = ec2.connection.EC2Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
    reservations = ec2conn.get_all_instances()
    instances = [i for r in reservations for i in r.instances]

    for i in instances:
        size = str(i.instance_type)
        current_state = str(i.state)

        if 'running' in current_state:
            if '.micro' in size:
                noscan += 1
            elif '.small' in size:
                noscan += 1
            else:
                ip_list.append(str(i.private_ip_address))

    print "Not including " + str(noscan) + " instances in scan profile."

    return ip_list


def add_asset(sc, asset_name, asset_ips, asset_description):
    sc.post('asset', json={
        'context': '',
        'createdTime': 0,
        'modifiedTime': 0,
        'status': -1,
        'type': 'static',
        'name': asset_name,
        'definedIPs': asset_ips,
        'description': asset_description,
        'tags': "",
    })

    print '** Imported %s using %s' % (asset_name, asset_ips)


def update_asset(sc, asset_id, asset_ips_updates):

    # Example Use:
    #   sc.patch('asset/45', json={'definedIPs':'10.0.0.1,10.0.0.2,10.0.0.3'})

    sc.patch('asset/%s' % asset_id, json={'definedIPs': ','.join(asset_ips_updates)})

    print "Asset : %s updated with %s IP Addresses : %s" % (asset_id, str(len(asset_ips_updates)), ','.join(asset_ips_updates))


if __name__ == '__main__':
    # Get the needed login info from the user...
    host = raw_input('SecurityCenter Server : ')
    scname = raw_input('SecurityCenter Username : ')
    scpass = getpass.getpass('SecurityCenter Password : ')
    AWS_Access_Key = getpass.getpass('AWS_ACCESS_KEY_ID : ')
    AWS_Secret_Key = getpass.getpass('AWS_SECRET_ACCESS_KEY : ')

    # Get all running instances, minus micros and smalls, from AWS account.
    available_ips = get_AWS_instances(AWS_Access_Key,AWS_Secret_Key)

    # Log into Security Center
    sc = SecurityCenter5(host)
    sc.login(scname,scpass)

    # Update SC5 asset record
    update_asset(sc, str(45), available_ips)

from pysecuritycenter.

vitalisec avatar vitalisec commented on July 17, 2024

I updated my pysecuritycenter to the latest version and still getting the following error. Odd thing is, this above code works for one account and will not work for my 2 other AWS accounts.

Traceback (most recent call last):
File "AWS_to_SC5.py", line 76, in
sc.login(scname,scpass)
File "/Library/Python/2.7/site-packages/securitycenter/sc5.py", line 45, in login
self._token = resp.json()['response']['token']
KeyError: 'token'

from pysecuritycenter.

SteveMcGrath avatar SteveMcGrath commented on July 17, 2024

is the login information valid?

from pysecuritycenter.

vitalisec avatar vitalisec commented on July 17, 2024

Yes. Found the issue. We enabled session management with a limit of 1 session per each user account. The account being used for the update was logged in when the script kicked off. I was able to update all of my asset groups.

from pysecuritycenter.

SteveMcGrath avatar SteveMcGrath commented on July 17, 2024

Glad to hear that the issue was external to the API ;) I'll close the issue now.

from pysecuritycenter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.