Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #16

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Dev #16

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:10

# Create app directory
WORKDIR /var/lib/jenkins/workspace/VFS-MultiEnv/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package.json ./

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

EXPOSE 8080
CMD [ "node", "Sample.js" ]
Binary file added geckodriver-v0.26.0-win32.zip
Binary file not shown.
74 changes: 74 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
LambdaTest selenium automation sample example
Configuration
----------
username: Username can be found at automation dashboard
accessToken: AccessToken can be generated from automation dashboard or profile section

Result
-------
Execute NodeJS Automation Tests on LambdaTest Distributed Selenium Grid
*/
const webdriver = require('selenium-webdriver');

/*
Setup remote driver
Params
----------
platform : Supported platform - (Windows 10, Windows 8.1, Windows 8, Windows 7, macOS High Sierra, macOS Sierra, OS X El Capitan, OS X Yosemite, OS X Mavericks)
browserName : Supported platform - (chrome, firefox, Internet Explorer, MicrosoftEdge, Safari)
version : Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/
*/

// username: Username can be found at automation dashboard
const USERNAME = 'ajaykorni';

// AccessKey: AccessKey can be generated from automation dashboard or profile section
const KEY = 'ajaykorni';

// gridUrl: gridUrl can be found at automation dashboard
const GRID_HOST = 'facebook.com';

function searchTextOnGoogle() {

// Setup Input capabilities
const capabilities = {
platform: 'ubuntu',
browserName: 'chrome',
version: '67.0',
resolution: '1280x800',
network: true,
visual: true,
console: true,
video: true,
name: 'Test 1', // name of the test
build: 'NodeJS build' // name of the build
}

// URL: https://{username}:{accessToken}@beta-hub.lambdatest.com/wd/hub
const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_HOST;

// setup and build selenium driver object
const driver = new webdriver.Builder()
.usingServer(gridUrl)
.withCapabilities(capabilities)
.build();

// navigate to a url, search for a text and get title of page
driver.get('https://www.google.com/ncr').then(function() {
driver.findElement(webdriver.By.name('q')).sendKeys('LambdaTest\n').then(function() {
driver.getTitle().then(function(title) {
setTimeout(function() {
console.log(title);
driver.executeScript('lambda-status=passed');
driver.quit();
}, 5000);
});
});
}).catch(function(err){
console.log("test failed with reason "+err)
driver.executeScript('lambda-status=failed');
driver.quit();
});
}
searchTextOnGoogle();
14 changes: 14 additions & 0 deletions job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: batch/v1
kind: Job
metadata:
name: kube-hunter
spec:
template:
spec:
containers:
- name: kube-hunter
image: aquasec/kube-hunter
command: ["python", "kube-hunter.py"]
args: ["--pod"]
restartPolicy: Never
backoffLimit: 4
130 changes: 130 additions & 0 deletions kube-hunter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env python3

import argparse
import logging
import threading

from kube_hunter.conf import config
from kube_hunter.modules.report.plain import PlainReporter
from kube_hunter.modules.report.yaml import YAMLReporter
from kube_hunter.modules.report.json import JSONReporter
from kube_hunter.modules.report.dispatchers import STDOUTDispatcher, HTTPDispatcher
from kube_hunter.core.events import handler
from kube_hunter.core.events.types import HuntFinished, HuntStarted
from kube_hunter.modules.discovery.hosts import RunningAsPodEvent, HostScanEvent


loglevel = getattr(logging, config.log.upper(), logging.INFO)

if config.log.lower() != "none":
logging.basicConfig(level=loglevel, format='%(message)s', datefmt='%H:%M:%S')

reporters = {
'yaml': YAMLReporter,
'json': JSONReporter,
'plain': PlainReporter
}

if config.report.lower() in reporters.keys():
config.reporter = reporters[config.report.lower()]()
else:
logging.warning('Unknown reporter selected, using plain')
config.reporter = reporters['plain']()

dispatchers = {
'stdout': STDOUTDispatcher,
'http': HTTPDispatcher
}

if config.dispatch.lower() in dispatchers.keys():
config.dispatcher = dispatchers[config.dispatch.lower()]()
else:
logging.warning('Unknown dispatcher selected, using stdout')
config.dispatcher = dispatchers['stdout']()

import kube_hunter


def interactive_set_config():
"""Sets config manually, returns True for success"""
options = [("Remote scanning", "scans one or more specific IPs or DNS names"),
("Interface scanning","scans subnets on all local network interfaces"),
("IP range scanning","scans a given IP range")]

print("Choose one of the options below:")
for i, (option, explanation) in enumerate(options):
print("{}. {} ({})".format(i+1, option.ljust(20), explanation))
choice = input("Your choice: ")
if choice == '1':
config.remote = input("Remotes (separated by a ','): ").replace(' ', '').split(',')
elif choice == '2':
config.interface = True
elif choice == '3':
config.cidr = input("CIDR (example - 192.168.1.0/24): ").replace(' ', '')
else:
return False
return True


def list_hunters():
print("\nPassive Hunters:\n----------------")
for hunter, docs in handler.passive_hunters.items():
name, doc = hunter.parse_docs(docs)
print("* {}\n {}\n".format(name, doc))

if config.active:
print("\n\nActive Hunters:\n---------------")
for hunter, docs in handler.active_hunters.items():
name, doc = hunter.parse_docs(docs)
print("* {}\n {}\n".format( name, doc))


global hunt_started_lock
hunt_started_lock = threading.Lock()
hunt_started = False

def main():
global hunt_started
scan_options = [
config.pod,
config.cidr,
config.remote,
config.interface
]
try:
if config.list:
list_hunters()
return

if not any(scan_options):
if not interactive_set_config(): return

with hunt_started_lock:
hunt_started = True
handler.publish_event(HuntStarted())
if config.pod:
handler.publish_event(RunningAsPodEvent())
else:
handler.publish_event(HostScanEvent())

# Blocking to see discovery output
handler.join()
except KeyboardInterrupt:
logging.debug("Kube-Hunter stopped by user")
# happens when running a container without interactive option
except EOFError:
logging.error("\033[0;31mPlease run again with -it\033[0m")
finally:
hunt_started_lock.acquire()
if hunt_started:
hunt_started_lock.release()
handler.publish_event(HuntFinished())
handler.join()
handler.free()
logging.debug("Cleaned Queue")
else:
hunt_started_lock.release()


if __name__ == '__main__':
main()
31 changes: 31 additions & 0 deletions kubernetes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: Service
metadata:
name: hello-kubernetes
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: hello-kubernetes
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kubernetes
spec:
replicas: 3
selector:
matchLabels:
app: hello-kubernetes
template:
metadata:
labels:
app: hello-kubernetes
spec:
containers:
- name: hello-kubernetes
image: paulbouwer/hello-kubernetes:1.5
ports:
- containerPort: 8080
Loading