concept command in category system administration

appears as: commds, commd, The commd, commd, commds, command, The commds, A commd
Securing DevOps

This is an excerpt from Manning's book Securing DevOps.

  • Once deployed, the backdoor contacts the mother ship to receive further instructions using a command-and-control (C2) channel. C2 channels can take the form of an outbound IRC connection, HTML pages that contain special keywords hidden in the body of the page, or DNS requests with commands embedded in TXT records.
  • GRR provides a Docker image at grrdocker/grr that makes it easy to test the system. After retrieving the image with docker pull, start a local server using the command shown in the following listing. It launches a web interface on http://localhost:8000; the username is admin and the password is demo.

    Listing 9.20 A vulnerable Go web application that executes random commands
    package main
    import (
     "fmt"
     "log"
     "net/http"
     "os/exec"
     "strings"
    )
    func main() {
     http.HandleFunc("/exec",    #1  
     func(w http.ResponseWriter,    #1  
     r *http.Request) {    #1  
     cmd := r.FormValue("cmd")    #2  
     cmdParts := strings.Split(cmd, " ")    #2  
     args := cmdParts[1:]    #2  
     out, err := exec.Command(cmdParts[0],    #3  
     args...).Output()    #3  
      if err != nil {
       w.WriteHeader(http.StatusBadRequest)
       fmt.Fprintf(w, "failed with %q", err)
      } else {
     fmt.Fprintf(w, "%s", out)    #4  
      }
     })
     log.Fatal(http.ListenAndServe(":8080", nil))
    }
    
    #1   Declares an HTTP handler
    #2   Extracts the command to run from the cmd query string of the request
    #3   Executes the command locally
    #4   Returns the output to the client
    Learn Cisco Network Administration in a Month of Lunches

    This is an excerpt from Manning's book Learn Cisco Network Administration in a Month of Lunches.

    First, the steps to configure a Cisco device are substantially different from the steps to configure a Juniper device. The commands, terminology, and order in which you do things are different. Administering a mixed network requires knowing how to configure both platforms and getting them to interoperate. This book addresses only the Cisco side of things.

    Switch1#show ?
      aaa                Show AAA values
      access-expression  List access expression
      access-lists       List access lists
      adjacency          Adjacent nodes
      aliases            Display alias commands
      ...
    
      vtp                VTP information
      wsma               Show Web Services Management Agents information
      xdr                Show details about XDR
      xos                Cross-OS Library Information and Traces
      xsd-format         Show the ODM XSD for the command
    
    Switch1#show

    You can specify the reload time in minutes or in both hours and minutes. For example, if you wanted to reload the device in 1 hour, 15 minutes, you’d issue the command reload in 1:15. As an aside, using the reload in command can keep you from locking yourself out when making changes on a remote device. For example, if you’re working on a router in an office that you’re not in physical proximity to, you can schedule a reload for a few minutes out and then make your changes. If your changes cause you to lose connectivity, you have to wait a few minutes for the router to reload. Once it reloads, it’ll forget your changes, and then you can then connect back and try again.

    20.5. Commands used in this chapter

    In a disaster scenario, your focus is going to be on getting things up and running again, so there are a limited number of commands at your disposal. Table 20.1 lists those commands and when to use them.

    Table 20.1. Commands used in this chapter

    Function

    Command

    Configuration mode

    Description

    Reloading the device Reload in 15 N/A Schedules a reload 15 minutes from now
    Reloading the device Reload cancel N/A Cancels a scheduled reload
    Deleting the startup configuration Delete nvram:startup-config N/A Deletes the startup configuration from NVRAM
    Resetting the password confreg 0x2142 ROMMON Configures ROMMON to ignore the startup configuration
    Resetting the password config-register 0x2102 Global Configures ROMMON to load the startup configuration at boot time
    Functional and Reactive Domain Modeling

    This is an excerpt from Manning's book Functional and Reactive Domain Modeling.

    We call Debit a command and DebitOccurred an event. Both are messages generated and processed by the model, but they differ in semantics in a subtle way. Take note of these differences, as you’ll be dealing with commands and events quite differently when we talk about our domain model architecture.

    Figure 8.4. Commands update the application state and persist in the write model. The queries, on the other hand, use the read model.

    Commands are actions that can loosely be said to be the dual of events. At the implementation level, we talk about command handlers when we abstract the domain behaviors that a command could execute. These include creating or updating aggregates, performing business validations, adding to the write model, and doing any amount of interaction with external systems, such as sending email or pushing messages to the message queue. You know how to abstract side effects functionally, and you’ll use the same techniques in implementing command handlers. Command handlers are nothing more than abstractions that need to be evaluated for performing a bunch of actions leading to events being generated and added to the stream (write model). Figure 8.7 describes the flow of actions within a command handler that implements a function to debit an amount from a customer account.

    We’ve always valued compositionality; why should we forego it for commands? After all, commands are APIs, and we’d like to make them compositional. You should be able to compose larger commands out of smaller ones, just as we discussed composition of APIs in earlier chapters. Here’s an example from our domain. Suppose you have individual commands for debit and credit of accounts. Composing a transfer command by combining the two should be possible:

    def transfer(from: String, to: String,
      amount: Amount): Command[Unit] = for {
        _ <- debit(from, amount)
        _ <- credit(to, amount)
      } yield ()

    Remember, you got similar compositionality with our domain service APIs in chapter 5. Do you recollect the technique you used? Yes! Free monads.[6] They’re ready to make a comeback in our implementation of event-sourced domain models. You’ll define commands as free monads over events so that you can combine commands monadically to build the algebra of our model behavior. You can learn all the details in the next section.