{"id":19328477,"url":"https://github.com/tmhsdigital/offensive-defense-methods","last_synced_at":"2025-02-24T06:40:39.782Z","repository":{"id":250107605,"uuid":"833471721","full_name":"TMHSDigital/offensive-defense-methods","owner":"TMHSDigital","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-25T06:59:54.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-06T07:28:30.929Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TMHSDigital.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"custom":null}},"created_at":"2024-07-25T06:03:43.000Z","updated_at":"2024-07-25T06:59:56.000Z","dependencies_parsed_at":"2024-07-25T08:19:11.166Z","dependency_job_id":null,"html_url":"https://github.com/TMHSDigital/offensive-defense-methods","commit_stats":null,"previous_names":["tmhsdigital/offensive-defense-methods"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TMHSDigital%2Foffensive-defense-methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TMHSDigital%2Foffensive-defense-methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TMHSDigital%2Foffensive-defense-methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TMHSDigital%2Foffensive-defense-methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TMHSDigital","download_url":"https://codeload.github.com/TMHSDigital/offensive-defense-methods/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240434181,"owners_count":19800546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T02:22:25.131Z","updated_at":"2025-02-24T06:40:39.703Z","avatar_url":"https://github.com/TMHSDigital.png","language":"Jupyter Notebook","readme":"# Offensive Security Techniques\n\n![GitHub stars](https://img.shields.io/github/stars/TMHSDigital/offensive-defense-methods?style=social)\n![GitHub forks](https://img.shields.io/github/forks/TMHSDigital/offensive-defense-methods?style=social)\n![GitHub watchers](https://img.shields.io/github/watchers/TMHSDigital/offensive-defense-methods?style=social)\n![GitHub issues](https://img.shields.io/github/issues/TMHSDigital/offensive-defense-methods)\n![GitHub pull requests](https://img.shields.io/github/issues-pr/TMHSDigital/offensive-defense-methods)\n![GitHub](https://img.shields.io/github/license/TMHSDigital/offensive-defense-methods)\n\n![Python](https://img.shields.io/badge/Python-3.8+-blue?logo=python\u0026logoColor=white)\n![Shell](https://img.shields.io/badge/Shell-Bash-blue?logo=gnu-bash\u0026logoColor=white)\n![Machine Learning](https://img.shields.io/badge/Machine%20Learning-Scikit--learn-orange?logo=scikit-learn\u0026logoColor=white)\n\n---\n\nThis repository provides examples of offensive security techniques, including ethical hacking (penetration testing), digital counter-intelligence, and the use of AI and machine learning for anomaly detection and automated responses.\n\n## Table of Contents\n1. [Ethical Hacking (Penetration Testing)](#ethical-hacking-penetration-testing)\n2. [Digital Counter-Intelligence](#digital-counter-intelligence)\n3. [Use of AI and Machine Learning](#use-of-ai-and-machine-learning)\n4. [File and Directory Structure](#file-and-directory-structure)\n5. [Disclaimer](#disclaimer)\n6. [Contributing](#contributing)\n7. [Resources](#resources)\n8. [License](#license)\n\n---\n\n## Ethical Hacking (Penetration Testing)\n\n### Description\nPenetration testing involves simulating attacks on a system to find vulnerabilities. This section demonstrates how to use Nmap for network scanning and a Python script for port scanning.\n\n### Nmap Command for Network Scanning\n```bash\n# Basic Nmap scan to discover open ports\nnmap -sS -p 1-65535 192.168.1.1\n```\n\n### Python Script for Port Scanning\n```python\nimport nmap\n\n# Initialize the Nmap PortScanner\nnm = nmap.PortScanner()\n\n# Scan the target IP address\ntarget = '192.168.1.1'\nnm.scan(target, '1-1024')\n\n# Print the scan results\nfor host in nm.all_hosts():\n    print(f'Scanning {host}')\n    for proto in nm[host].all_protocols():\n        print(f'Protocol: {proto}')\n        lport = nm[host][proto].keys()\n        for port in sorted(lport):\n            print(f'Port: {port}\\tState: {nm[host][proto][port][\"state\"]}')\n```\n\n---\n\n## Digital Counter-Intelligence\n\n### Description\nDigital counter-intelligence involves tracking and monitoring attacker activities. This section demonstrates setting up a Cowrie honeypot to log brute force attacks and shell interaction performed by attackers.\n\n### Setting Up Cowrie (Shell Commands)\n```bash\n# Install prerequisites\nsudo apt-get update\nsudo apt-get install -y git python3-virtualenv libssl-dev libffi-dev build-essential\n\n# Clone the Cowrie repository\ngit clone http://github.com/cowrie/cowrie\n\n# Set up the virtual environment\ncd cowrie\nvirtualenv cowrie-env\nsource cowrie-env/bin/activate\n\n# Install Cowrie dependencies\npip install --upgrade pip\npip install -r requirements.txt\n\n# Start Cowrie\nbin/cowrie start\n```\n\n---\n\n## Use of AI and Machine Learning\n\n### Description\nAI and ML can be used to detect anomalies and respond to threats in real-time. This section demonstrates how to build an anomaly detection model using scikit-learn and an automated response script to block malicious IPs.\n\n### Anomaly Detection with Machine Learning\n```python\nimport numpy as np\nfrom sklearn.ensemble import IsolationForest\n\n# Generate synthetic data for demonstration\nX = np.random.rand(100, 2)\nX_outliers = np.random.uniform(low=-1, high=1, size=(20, 2))\nX = np.concatenate([X, X_outliers], axis=0)\n\n# Fit the model\nclf = IsolationForest(random_state=42, contamination=0.1)\nclf.fit(X)\n\n# Predict anomalies\ny_pred = clf.predict(X)\n\n# Output the results\nfor i, pred in enumerate(y_pred):\n    if pred == -1:\n        print(f\"Anomaly detected at index {i}: {X[i]}\")\n```\n\n### Automated Response: Blocking IPs with Python\n```python\nimport os\nimport subprocess\n\n# List of malicious IPs detected\nmalicious_ips = ['192.168.1.100', '10.0.0.5']\n\n# Block each malicious IP using iptables\nfor ip in malicious_ips:\n    command = f'sudo iptables -A INPUT -s {ip} -j DROP'\n    subprocess.call(command, shell=True)\n    print(f\"Blocked IP: {ip}\")\n```\n\n## File and Directory Structure\n\n```plaintext\n.\n├── README.md\n├── ethical_hacking\n│   └── port_scanner.py\n├── digital_counter_intelligence\n│   └── setup_cowrie.sh\n└── ai_ml\n    ├── anomaly_detection.py\n    └── block_ips.py\n```\n\n---\n\n### ethical_hacking/port_scanner.py\nPython script for port scanning using Nmap.\n\n### digital_counter_intelligence/setup_cowrie.sh\nShell script for setting up the Cowrie honeypot.\n\n### ai_ml/anomaly_detection.py\nPython script for anomaly detection using machine learning.\n\n### ai_ml/block_ips.py\nPython script for blocking malicious IPs using iptables.\n\n---\n\n## Disclaimer\n\n**IMPORTANT:** The techniques and tools provided in this repository are intended solely for educational purposes. Unauthorized use of these techniques and tools for malicious or unethical purposes is strictly prohibited. The authors of this repository are not responsible for any misuse or damage caused by the use of these techniques and tools.\n\n---\n\n## Contributing\nContributions are welcome! Please read our [Contributing Guidelines](CONTRIBUTING.md) for more information.\n\n---\n\n## Resources\n- [Books and Articles](resources/books.md)\n- [Online Courses](resources/courses.md)\n- [Tools and Utilities](resources/tools.md)\n\n---\n\n## License\nThis project is licensed under the \"Do No Harm\" License - see the [LICENSE](LICENSE) file for details.\n```\n\n``````\nDO NO HARM LICENSE\n\nCopyright (c) 2024 [TM Hospitality Strategies]\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nThe software is provided \"as is\", without warranty of any kind, express or\nimplied, including but not limited to the warranties of merchantability,\nfitness for a particular purpose and noninfringement. In no event shall the\nauthors or copyright holders be liable for any claim, damages or other\nliability, whether in an action of contract, tort or otherwise, arising from,\nout of or in connection with the software or the use or other dealings in the\nsoftware.\n\n## \"Do No Harm\" Clause\n\nThe software may not be used by any person or entity for systems, activities,\nor projects that result in:\n  1. physical injury or loss of life,\n  2. environmental damage or destruction,\n  3. unjust discrimination or oppression,\n  4. violation of privacy or personal data,\n  5. support of unlawful activities.\n\nBy using the software, you agree to be bound by this clause and use the software\nonly for lawful and ethical purposes.\n```\n\n# Contributing to Offensive Security Techniques\n\nThank you for considering contributing to this repository! We welcome contributions in the form of bug reports, feature requests, code improvements, and documentation enhancements.\n\n## How to Contribute\n\n1. **Fork the Repository**\n   - Click on the \"Fork\" button at the top right of this page to create a copy of this repository in your GitHub account.\n\n2. **Clone the Repository**\n   - Clone your forked repository to your local machine.\n   ```bash\n   git clone https://github.com/your-username/offensive-defense-methods.git\n   cd offensive-defense-methods\n   ```\n\n3. **Create a Branch**\n   - Create a new branch for your changes.\n   ```bash\n   git checkout -b my-feature-branch\n   ```\n\n4. **Make Changes**\n   - Make your changes to the code, documentation, or other files.\n\n5. **Commit Changes**\n   - Commit your changes with a descriptive message\n\n.\n   ```bash\n   git add .\n   git commit -m \"Description of the changes\"\n   ```\n\n6. **Push Changes**\n   - Push your changes to your forked repository.\n   ```bash\n   git push origin my-feature-branch\n   ```\n\n7. **Create a Pull Request**\n   - Go to the original repository on GitHub and create a pull request from your forked repository.\n\n## Code Style\n\n- Follow PEP 8 for Python code.\n- Use descriptive variable names and comments.\n- Ensure code is well-documented.\n\n## Reporting Issues\n\n- Check existing issues to avoid duplicates.\n- Provide a clear and descriptive title.\n- Include steps to reproduce the issue.\n\n## Code of Conduct\n\nPlease adhere to the [Code of Conduct](CODE_OF_CONDUCT.md) in all your interactions with the project.\n\nThank you for your contributions!\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmhsdigital%2Foffensive-defense-methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmhsdigital%2Foffensive-defense-methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmhsdigital%2Foffensive-defense-methods/lists"}