-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor expect step, increase test coverage, update pre-commit config (
#503) Summary: Pull Request resolved: #503 **Added:** - `ssh-pw-expect.yaml`: Demonstrate expect step with SSH password. - `expect.yaml`: Added YAML front matter for better structuring. - Introduced `ExpectSpec` struct to encapsulate expect script and responses. - Detailed comments for `ExpectSpec` attributes. - Enhanced validation for `ExpectStep`, ensuring `ExpectSpec` is provided. - Dynamic timeout handling in expect responses. - `.semgrepignore` to avoid creating false positives with tests and examples **Changed:** - Refactored `expectstep.go`: - Introduced `ExpectSpec` for inline script and responses. - Improved validation and execution logic for expect steps. - Refactored `Execute` method to accommodate `ExpectSpec`. - Updated `prepareCommand` method to use `ExpectSpec` inline script. - Enhanced logging and error messages in `Execute` and `Validate` methods. - Updated `expectstep_test.go`: - Mocked SSH interaction within expect steps. - Refactored test cases for better coverage. - Improved logging and error handling across `expectstep.go`. - Updated tests to reflect changes in `ExpectStep` structure and logic. **Removed:** - `.pre-commit-config.yaml`: Removed `go-vet` hook for streamlined configuration. - Removed unnecessary imports and streamlined existing ones. Reviewed By: w51d Differential Revision: D60238880 fbshipit-source-id: 8930ad1d6d59900a3be49a65682b3199c1312f5a
- Loading branch information
1 parent
ac09704
commit 3cfe49e
Showing
9 changed files
with
652 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Items added to this file will be ignored by Semgrep. | ||
# | ||
# This file uses .gitignore syntax: | ||
# | ||
# To ignore a file anywhere it occurs in your project, enter a | ||
# glob pattern here. E.g. "*.min.js". | ||
# | ||
# To ignore a directory anywhere it occurs in your project, add | ||
# a trailing slash to the file name. E.g. "dist/". | ||
# | ||
# To ignore a file or directory only relative to the project root, | ||
# include a slash anywhere except the last character. E.g. | ||
# "/dist/", or "src/generated". | ||
# | ||
# Some parts of .gitignore syntax are not supported, and patterns | ||
# using this syntax will be dropped from the ignore list: | ||
# - Explicit "include syntax", e.g. "!kept/". | ||
# - Multi-character expansion syntax, e.g. "*.py[cod]" | ||
# To include ignore patterns from another file, start a line | ||
# with ':include', followed by the path of the file. E.g. | ||
# ":include path/to/other/ignore/file". | ||
# UPDATE: this will not be be needed in osemgrep which supports | ||
# all of the .gitignore syntax (!kept/, *.py[cod]) | ||
# | ||
# To ignore a file with a literal ':' character, escape it with | ||
# a backslash, e.g. "\:foo". | ||
|
||
# Tests | ||
*_test* | ||
|
||
# Examples | ||
example-ttps/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
api_version: 2.0 | ||
uuid: 891a38dc-4b2f-4614-9960-a66a7e9499ab | ||
name: Expect step with SSH password | ||
description: | | ||
This TTP demonstrates the usage of an expect step to automate interaction | ||
with an SSH server using a password. | ||
args: | ||
- name: ssh_host | ||
description: The hostname or IP address of the SSH server | ||
default: target-system | ||
- name: ssh_user | ||
description: The username to use for the SSH connection | ||
default: bobbo | ||
- name: ssh_password | ||
description: The password to use for the SSH connection | ||
default: "Password123!" | ||
requirements: | ||
platforms: | ||
- os: darwin | ||
- os: windows | ||
- os: linux | ||
steps: | ||
- name: run_expect_script | ||
expect: | ||
inline: | | ||
if command -v sshpass >/dev/null 2>&1; then | ||
sshpass -p "{{ .Args.ssh_password }}" ssh {{ .Args.ssh_user }}@{{ .Args.ssh_host }} | ||
else | ||
echo "Error: sshpass is not installed. Please install it before running this script." | ||
exit 1 | ||
fi | ||
responses: | ||
- prompt: "Welcome to Ubuntu" | ||
response: "whoami" | ||
- prompt: "{{ .Args.ssh_user }}" | ||
response: "exit" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.