SANTA CLARA – When former 49ers cornerback Shareece Wright signed with the Baltimore Ravens on Monday, much of the talk was about how his inside knowledge could help his new team plot against his old team.

On Sunday, it worked the other way.

Wright surrendered a 76-yard touchdown pass to Torrey Smith on a stop-and-go, and he slipped and gave up a 21-yard scoring pass to Quinton Patton in the fourth quarter.

The 49ers held on for a 25-20 victory over the Baltimore Ravens, and their knowledge of Wright was a big reason they were able to snap a four-game losing streak.

When asked if knowledge of Wright’s game factored into the 49ers’ attack, receiver Anquan Boldin answered, “Definitely. When you have a guy on your team for that long, you get to see him every day in practice, you understand his weaknesses, as well as his strengths. That was one of the big things we wanted to attack.”

[INSTANT REPLAY: Kap comes alive, slings 49ers past Ravens]

Quarterback Colin Kaepernick had his second consecutive strong day, completing 16 of 27 passes for 340 yards and two touchdowns.

Wright signed with the 49ers in the offseason and, for a while, appeared to be ticketed as a starter. But he lost his job early in training camp and was inactive for the first four games of the regular season before the 49ers released him to make room for guard Andrew Tiller.

Meanwhile, the Ravens were decimated by injuries to defensive backs. Not only was he active for Sunday’s game, but he was forced into action. And his presence was something the 49ers felt they could exploit.

“I think being around any player, you pick up on their tendencies,” Kaepernick said. “You pick up on what you can take advantage of. There were a couple of things we felt we could take advantage of, and we did.”

The 49ers targeted Wright with a deep throw to Smith in the second quarter.

“This was my first game," Wright said. "I gave up a big play and that’s on me. I’ll take ownership of that. I can’t allow that to happen.”

Kaepernick came back to hit Patton with the touchdown on a play he extended. Wright fell down while in coverage.

"Our feet got caught up," Wright said. "He kept his balance and I didn’t.”

The 49ers also took advantage of Kaepernick’s ability to make plays on the run in Sunday’s game. In addition to the touchdown pass to Patton, Kaepernick also found Boldin on a 51-yard pass play on a scramble drill.

“Our receivers were doing a great job,” Kaepernick said. “Anquan kept running out the one. We had a huge play off of that. We had the touchdown on Quinton’s. Our receivers are working. They’re working hard to make sure we’re doing everything we can to make plays.

“It’s also a huge praise to the offensive line because they’re giving us enough time to allow those scramble drills to happen.”