Git Product home page Git Product logo

dne-security-code's Introduction

Cisco DevNet DevNet Express Security Track Code

This repository contains the sample code to go along with Cisco DevNet Learning Labs covering security topics. During the setup steps of the labs, you'll be asked to clone this repository down to your workstation to get started.

Getting started

  1. Go to https://developer.cisco.com/learning/tracks/devnet-express-security#dne-security-verify and login or register if you're not registered.
  2. Follow the instructions in the lab. The lab environment offers a step-by-step path to configure and run the examples of this repository.

Technical requirements

You may either do the labs in the virtual environment offered by Cisco or configure your own environment on your desktop.

Accessing Cisco virtual lab environment

You need a PC or MAC with the following software:

Working on your own desktop

Python 3.6

Python is required to run the sample scripts.

You have to install Python 3.6. We suggest that you work in a virtual environment to work with Python. If you want to know more about virtual env, this document is an excellent introduction http://christopher5106.github.io/python/2017/10/12/python-packages-and-their-managers-apt-yum-easy_install-pip-virtualenv-conda.html. The lab explains how to install virtual-env. You can work with Miniconda as an alternative. To install Miniconda, follow the official instructions here: https://conda.io/miniconda.html.

Postman

You use Postman to test REST API calls in a graphical environment. To install Postman, follow the official instructions here: https://learning.getpostman.com/docs/postman/launching_postman/installation_and_updates/.

Creating virtual env with Conda

You should run the following commands on Linux to create a virtual environment with Conda:

$conda create --name cisco python=3.6
$source activate cisco

and you're done!

Contributing

Contributions are welcome, and we are glad to review changes through pull requests. See contributing.md for details.

The goal of these learning labs is to ensure a 'hands-on' learning approach rather than just theory or instructions.

About this Sample Code

Contributions are welcome, and we are glad to review changes through pull requests. See contributing.md for details.

Within this repository are several files and folders covering different topics and labs. This table provides details on what each is used for, and which labs they correspond to.

File / Folder Description
env_lab.py A Python file containing lab infrastructure details for routers, switches and appliances leveraged in the different labs. This file provides a centralized Python import that is used in other code samples to retrieve IPs, usernames, and passwords for connections
env_user.template Similar to env_lab.py, this is a template for end users to copy within their own code repo as env_user.py where they can provide unique details for their own accounts. For example, their Webex Teams (formerly Cisco Spark) authentication token. Not all labs require this file, if one does it will be specified in setup.
requirements.txt Global Python requirements file containing the requirements for all labs within this repository. Each folder also contains a local requirements.txt file.
intro-python-code/ Sample code and exercises for the Python Fundamentals Learning Labs Pulled in through a file copy in November 2018. Note that the submodule tracks with the master branch, but solutions are on the solution branch in the original CiscoDevNet/intro-python-code repository.
intro-rest-api/ Sample code and exercises for the REST API Fundamentals Learning Labs Pulled in through a file copy in November 2018.
intro-umbrella/ Sample code and exercises for the Introduction to Cisco Umbrella Learning Labs
(Publishing Soon)
verify/ A series of verification scripts primarily used during DevNet Express events to ensure the workshop environment is fully operational.
dev/ Resources and information for building code samples and labs.
requirements-dev.txt Python requirements file containing requirements only needed if developing new code samples.

Note: These code samples are also leveraged during DevNet Express events. If you are one of these events, your event proctors and hosts will walk you through event setup and verification steps as part of agenda.

Note: the mission-data directory contains the answsers in JSON files. This is as last resort only when the attendee is not able to solve it. Make sure that the attendees don't use this to "cheat".

Contributing

These learning modules are for public consumption, so you must ensure that you have the rights to any content that you contribute.

Getting Involved

  • If you’re a Cisco employee and would like to have access to make changes yourself, please add your GitHub ID and we’ll get in touch.
  • If you'd like to contribute to an existing lab, refer to contributing.md.
  • If you're interested in creating a new Cisco DevNet Learning Lab, please contact a DevNet administrator for guidance.

dne-security-code's People

Contributors

ageev avatar agentlecisco avatar annegentle avatar chrivand avatar cmlccie avatar jemunos avatar klevenstein avatar mdautrey avatar oborys avatar oxsannikova avatar vasquezthered avatar veeratcisco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dne-security-code's Issues

directory name standardization

Could we please standardize the directory names?
Some have the "dne-security" prefix, eg dne-security-fdm-code
Some don't, eg amp-code

Can we please pick one or the other, and stick to it?
Thank you

ISE non-pythonic code - ise_mission.py

ise_mission.py

In the function ‘post_to_ise’ the payload is created in an extremely non-pythonic way. The nice thing is that there is a function in the code that can do it in a pythonic way: ‘createPayload’ (by the way: the function name is non-PEP8)

Original code

def post_to_ise(maclist, namelist):
    #TODO: Create the URL for the PUT request to apply the ANC policy! Hint: Make sure you pass the Auth paramenters for the API call
    url = MISSION
    env_lab.print_missing_mission_warn(env_lab.get_line())
    
    for items in maclist:
        payload = "{\r\n    \"OperationAdditionalData\": {\r\n    \"additionalData\": [{\r\n    \"name\": \"macAddress\",\r\n    \"value\": \""+ items + "\"\r\n    },\r\n    {\r\n    \"name\": \"policyName\",\r\n    \"value\": \"" + namelist + '"' + "\r\n    }]\r\n  }\r\n}"
        print(json.dumps(payload,sort_keys=True,indent=3))
        response = requests.request("PUT", url, data=payload, verify=False, headers=headers)
        if(response.status_code == 204):
            print("Done!..Applied Quarantine policy to the rogue endpoint...MAC: {0} Threat is now contained....".format(items))
        else:
            print("An error has ocurred with the following code %(error)s" % {'error': response.status_code})

Proposed code:
Import HTTPBasisAuth
Create the payload with the available function
Change the request call, added json=payload in stead of data=payload and added authentication

from requests.auth import HTTPBasicAuth
 
def post_to_ise(maclist, namelist):
    #TODO: Create the URL for the PUT request to apply the ANC policy! Hint: Make sure you pass the Auth paramenters for the API call
    url = MISSION
    env_lab.print_missing_mission_warn(env_lab.get_line())

    authentication = HTTPBasicAuth(username, password)
    for items in maclist:
        payload = createPayload(items, namelist)
        print(json.dumps(payload, sort_keys=True, indent=3))
        response = requests.put(url, json=payload, verify=False, headers=headers, auth=authentication)
        if response.status_code == 204:
            print("Done!..Applied Quarantine policy to the rogue endpoint...MAC: {0} Threat is now contained....".format(items))
        else:
            print("An error has ocurred with the following code %(error)s" % {'error': response.status_code})

AMP step 2 JSON pretty print

https://developer.cisco.com/learning/tracks/devnet-express-security/ampforendpoints/intro-into-amp-apis/step/2

Lab guide says:
"You should see a print out to the screen that looks similar to the section below: "
followed by JSON in a pretty format with colors

However, the code just outputs one big ugly blob of JSON text.

So either the lab guide needs to be corrected to match the code, or (preferably) the step2.py code needs to be corrected to json.dumps the JSON all pretty.

(thanks to John Frame for pointing it out)

Need to update the README(s)

They are a little boring today and could use some spicing up! Additionally, the contents need to be updated to reflect the v1.1 repo restructuring, coding patterns (use the env_lab.py and env_user.py configuration files), and lab/mission workflows.

umbrella pagination with get request not working - EnforcementGetRequest.py

"url_get" variable is not updated correctly in the while loop, causing the next page not to load.

https://github.com/CiscoDevNet/dne-security-code/blob/master/intro-umbrella/EnforcementGetRequest.py

Original code

# keep doing GET requests, until looped through all domains
while True:
    req = requests.get(url_get)
    json_file = req.json()
    for row in json_file["data"]:
        domain_list.append(row["name"])
    # GET requests will only list 200 domains, if more than that, it will request next bulk of 200 domains
    if bool(json_file["meta"]["next"]):
        Url = json_file["meta"]["next"]
    # break out of loop when finished
    else:    
        break

Fixed code

# keep doing GET requests, until looped through all domains
while True:
    req = requests.get(url_get)
    json_file = req.json()
    for row in json_file["data"]:
        domain_list.append(row["name"])
    # GET requests will only list 200 domains, if more than that, it will request next bulk of 200 domains
    if bool(json_file["meta"]["next"]):
        url_get = json_file["meta"]["next"]
    # break out of loop when finished
    else:    
        break

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.