Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
qu35t-code committed Jan 27, 2024
2 parents 2485d05 + 43a1963 commit 645c350
Show file tree
Hide file tree
Showing 24 changed files with 1,274 additions and 192 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
QU35T-code
27 changes: 27 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix
- [ ] New feature
- [ ] This change requires a documentation update

# How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

- [ ] Test A
- [ ] Test B

# Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] My changes generate no new warnings
21 changes: 1 addition & 20 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,4 @@ jobs:
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
run: go build -v ./...

update-version:
needs: build
if: github.ref == 'refs/heads/dev'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: 'dev'
- name: Update Version in config.go
run: |
sed -i "s/const Version = \".*\"/const Version = \"$GITHUB_SHA\"/" config/config.go
- name: Commit and Push
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github Action"
git add config/config.go
git commit -m "Update dev version to $GITHUB_SHA"
git push origin HEAD:dev
run: go build -v ./...
128 changes: 128 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[email protected].
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series
of actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't hesitate to contribute to the project with a pull request. All ideas are welcome to improve the project !
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<div>
<img alt="current version" src="https://img.shields.io/badge/linux-supported-success">
<img alt="current version" src="https://img.shields.io/badge/windows-supported-success">
<img alt="current version" src="https://img.shields.io/badge/WSL-supported-success">
<img alt="current version" src="https://img.shields.io/badge/mac-supported-success">
<br>
<img alt="amd64" src="https://img.shields.io/badge/amd64%20(x86__64)-supported-success">
Expand Down
80 changes: 80 additions & 0 deletions cmd/getflag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package cmd

import (
"fmt"
"os"
"strings"

"github.com/GoToolSharing/htb-cli/config"
"github.com/GoToolSharing/htb-cli/lib/ssh"
"github.com/GoToolSharing/htb-cli/lib/submit"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

var getflagCmd = &cobra.Command{
Use: "getflag",
Short: "Retrieves and submits flags from an SSH connection (linux only)",
Run: func(cmd *cobra.Command, args []string) {
config.GlobalConfig.Logger.Info("Getflag command executed")
username, err := cmd.Flags().GetString("username")
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}
password, err := cmd.Flags().GetString("password")
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}
host, err := cmd.Flags().GetString("host")
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}
port, err := cmd.Flags().GetInt("port")
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}
connection, err := ssh.Connect(username, password, host, port)
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}
userFlag, err := ssh.GetUserFlag(connection)
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}
userFlag = strings.ReplaceAll(userFlag, "\n", "")
hostname, err := ssh.GetHostname(connection)
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}
connection.Close()
url, payload, err := ssh.BuildSubmitStuff(hostname, userFlag)
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}

message, err := submit.SubmitFlag(url, payload)
if err != nil {
config.GlobalConfig.Logger.Error("", zap.Error(err))
os.Exit(1)
}
fmt.Println(message)

config.GlobalConfig.Logger.Info("Exit getflag command correctly")
},
}

func init() {
rootCmd.AddCommand(getflagCmd)
getflagCmd.Flags().StringP("username", "u", "", "SSH username")
getflagCmd.Flags().StringP("password", "p", "", "SSH password")
getflagCmd.Flags().IntP("port", "P", 22, "(Optional) SSH Port (Default 22)")
getflagCmd.Flags().StringP("host", "", "", "(Optional) SSH host")
}
64 changes: 64 additions & 0 deletions cmd/hosts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package cmd

import (
"fmt"

"github.com/GoToolSharing/htb-cli/config"
"github.com/spf13/cobra"
)

var hostsCmd = &cobra.Command{
Use: "hosts",
Short: "Interact with hosts file",
Run: func(cmd *cobra.Command, args []string) {
config.GlobalConfig.Logger.Info("Hosts command executed")
fmt.Println("WIP")
// addParam, err := cmd.Flags().GetString("add")
// if err != nil {
// config.GlobalConfig.Logger.Error("", zap.Error(err))
// os.Exit(1)
// }

// deleteParam, err := cmd.Flags().GetString("delete")
// if err != nil {
// config.GlobalConfig.Logger.Error("", zap.Error(err))
// os.Exit(1)
// }

// ipParam, err := cmd.Flags().GetString("ip")
// if err != nil {
// config.GlobalConfig.Logger.Error("", zap.Error(err))
// os.Exit(1)
// }

// if addParam != "" && deleteParam != "" {
// config.GlobalConfig.Logger.Error("Only one parameter is allowed")
// os.Exit(1)
// }

// if addParam != "" {
// err = hosts.AddEntryToHosts(ipParam, addParam)
// if err != nil {
// config.GlobalConfig.Logger.Error("", zap.Error(err))
// os.Exit(1)
// }
// }

// if deleteParam != "" {
// err = hosts.RemoveEntryFromHosts(ipParam, deleteParam)
// if err != nil {
// config.GlobalConfig.Logger.Error("", zap.Error(err))
// os.Exit(1)
// }
// }

config.GlobalConfig.Logger.Info("Exit hosts command correctly")
},
}

func init() {
rootCmd.AddCommand(hostsCmd)
hostsCmd.Flags().StringP("add", "a", "", "Add a new entry")
hostsCmd.Flags().StringP("ip", "i", "", "IP Address")
hostsCmd.Flags().StringP("delete", "d", "", "Delete an entry")
}
Loading

0 comments on commit 645c350

Please sign in to comment.